Base64 Attachment REST API v1.3

This plugin provides a REST API that allows upload/download of Base64 encoded attachments:

  • Direct - allows direct upload / download of Base64 encoded attachments where metadata are stored in URL

  • JSON - allows upload of Base64 encoded attachments where both attachment and metadata are stored in JSON structure

  • SD Customer - allows upload / download of Base64 encoded attachments where both attachment and metadata are stored in JSON structure as a comment created by a Jira Service Management Agent / Customer

Authentication

All endpoints require preemptive basic authentication.

REST Endpoints

Direct endpoints

GET /rest/base64attachment/1.0/direct/{issueIdOrKey}

Allows direct download of base64 encoded attachment where metadata are in URL. The URL can be parametrized as follows:

  • {issueIdOrKey} - path parameter that should be replaced with the issue id or key

Additionally following optional query parameters may be used:

  • {filename} - if used, then find attachment by Filename displayed in Jira issue (Do not use together with parameter attachmentId)

    {attachmentId} - if used, then find attachment by ID (Do not use together with parameter filename)

  • {outputLineLength} - if used, then each line of encoded data will contain outputLineLength characters (rounded down to nearest multiple of 4)

Example:

curl -s -u <username>:<password> http://localhost:8080/rest/base64attachment/1.0/direct/SAM-43/?filename=sample.txt | base64 -di

GET /rest/base64attachment/1.0/direct/{issueIdOrKey}/{filename}/

Allows direct download of base64 encoded attachment where metadata are in URL. The URL can be parametrized as follows:

  • {issueIdOrKey} - path parameter that should be replaced with the issue id or key

  • {filename} - path parameter that should be replaced with Filename that will be displayed in Jira

Additionally following optional query parameters may be used:

  • {outputLineLength} - if used, then each line of encoded data will contain outputLineLength characters (rounded down to nearest multiple of 4)

Example:

curl -s -u <username>:<password> http://localhost:8080/rest/base64attachment/1.0/direct/SAM-43/sample.txt/?outputLineLength=76 | base64 -di

POST /rest/base64attachment/1.0/direct/{issueIdOrKey}/{filename}/

Allows direct upload of Base64 encoded attachments where metadata are stored in URL.

The URL can be parametrized as follows:

  • {issueIdOrKey} - path parameter that should be replaced with the issue id or key

  • {filename} - path parameter that should be replaced with filename that will be displayed in Jira

Additionally, following optional query parameters may be used:

  • contentType - if used, then Jira will store this content type for the uploaded attachment.  If not specified, then internal Jira functionality will decide best content type for uploaded attachment.

  • zipFlag - if used, then the zip flag will be passed to Jira to indicate that the uploaded attachment is a zip archive.

Example:

JSON endpoint

POST /rest/base64attachment/1.0/json

Allows upload of Base64 encoded attachments where both attachment and metadata are stored in JSON structure.

The JSON structure included in the body can be parameterized as follows:

  • issueIdOrKey - required parameter, should be replaced with the issue id or key

  • base64EncodedData - required parameter, should contain base64 encoded attachment data

  • filename - required parameter, should be replaced with filename that will be displayed in Jira

  • contentType - optional parameter, if used then Jira will store this content type for the uploaded attachment (If not specified, then internal Jira functionality will decide best content type for uploaded attachment)

  • zipFlag - optional parameter, if used then the zip flag will be passed to Jira to indicate that the uploaded attachment is a zip archive

Example:

URL

http://localhost:8080/rest/base64attachment/1.0/json

Method

POST

Content Type (HTTP Header)

application/json

Body

{ "issueKeyOrId" : "SAM-43", "base64EncodedData" : "SGVsbG8gd29ybGQhCg==", "filename" : "sample.txt", "zipFlag" : "false", "contentType" : "text/plain" }

SD Customer endpoint

WarningThe SD Customer endpoint is experimental and may stop working in future releases of Jira Service Desk / Manager and may remain unusable. Endpoint implementation utilizes experimental and internal Jira APIs due to the fact that no stable Jira Java API is available that provides this functionality. Use at your own risk!

GET /rest/base64attachment/1.0/sdcustomer/{issueIdOrKey}/{filename}

Allows download of Base64 encoded attachment where metadata are in URL. The URL can be parametrized as follows:

  • {issueIdOrKey} - path parameter that should be replaced with the issue id or key

  • {filename} - path parameter that should be replaced with Filename that will be displayed in Jira

Additionally following optional query parameters may be used:

  • {outputLineLength} - if used, then each line of encoded data will contain outputLineLength characters (rounded down to nearest multiple of 4)

Example:

curl -s -u <username>:<password> http://localhost:8080/rest/base64attachment/1.0/sdcustomer/SAM-43/sample.txt/?outputLineLength=76 | base64 -di

POST /rest/base64attachment/1.0/sdcustomer/json

Allows upload of Base64 encoded attachments where both attachment and metadata are stored in JSON structure as a public comment created by a Jira Service Management Agent / Customer.

The JSON structure included in the body can be parameterized as follows:

  • issueIdOrKey - required parameter, should be replaced with the issue id or key

  • additionalComment - required parameter, comment body as plain text

  • files - an array of attachments

    • base64EncodedData - required parameter, should contain base64 encoded attachment data

    • filename - required parameter, should be replaced with a filename that will be displayed in Jira

    • contentType - optional parameter, if used then Jira will store this content type for the uploaded attachment (If not specified, then internal Jira functionality will decide best content type for uploaded attachment)

Example:

URL

http://localhost:8080/rest/base64attachment/1.0/sdcustomer/json

Method

POST

Content Type (HTTP Header)

application/json

Body

{ "issueKeyOrId" : "SOP-2", "additionalComment" : "ajdfjsafajs", "files" : [ { "base64EncodedData" : "SGVsbG8gd29ybGQhCg==", "filename" : "abc.txt", "contentType" : "text/plain" }, { "base64EncodedData" : "SGVsbG8gd29ybGQhCg==", "filename" : "cde.txt", "contentType" : "text/plain" } ] }

API Response

This chapter describes the structure of the response that is returned by all API endpoints.

Success

All endpoints respond with a JSON response that contains the following fields when the API request was processed successfully:

  • result - OK, when the attachment was correctly created

  • attachmentId - attachment ID (Note: SD Customer endpoint does not return attachment ids)

Example:

Error

All endpoints respond usually with a JSON response that will contain the following fields when the API request processing failed:

  • result - ERROR

  • errorMessage - error message

The HTTP status code of an error response will be in the 4** or 5** range.

Example:

On this page: