How to add an attachment to a Jira Service Desk Cloud ticket using the REST APIs

Still need help?

The Atlassian Community is here for you.

Ask the community

Two (or more) different REST requests are needed in order to add attachment(s) to JIRA Service Desk issues:

  1. The first one(s) to add the attachments to the Service Desk calling the endpoint: servicedesk/{serviceDeskId}/attachTemporaryFile (2 requests to add 2 files in below example):

    curl -D- -u {USER}:{PASSWORD} -H "X-Atlassian-Token: nocheck" -H "X-ExperimentalApi: true" -F "file=@{/path/to/file/test2.txt}" -X POST https://{INSTANCE}{SERVICE_DESK_ID}/attachTemporaryFile
    HTTP/1.1 100 Continue
    HTTP/1.1 201 Created
    curl -D- -u {USER}:{PASSWORD} -H "X-Atlassian-Token: nocheck" -H "X-ExperimentalApi: opt-in" -F "file=@{/path/to/file/test3.txt}" -X POST{SERVICE_DESK_ID}/attachTemporaryFile
  2. The second request is to add the temporary files attached to the Service Desk at the previous step to a ticket by calling the endpoint: /rest/servicedeskapi/request/{issueIdOrKey}/attachment):

    curl -D- -u {USER}:{PASSWORD} -H "Accept: application/json" -H "Content-Type: application/json" -H "X-ExperimentalApi: opt-in" -d '{"additionalComment": {"body": "BODY OF THE COMMENT, IF ANY"}, "public": "true","temporaryAttachmentIds": ["5ad41f7b-882a-4f12-8a08-9b401d6dd3bf", "3f9ff4f9-99a0-4ee0-868e-8b93c8c67bee"]}' -X POST https://{INSTANCE}{ISSUE_ID}/attachment
    {"comment":{"_expands":["attachment","renderedBody"],"id":"10504","body":"BODY OF THE COMMENT, IF ANY: adding 2 attachments\n\n[^test2.txt] _(0.0 kB)_\n\n[^test3.txt] _(0.0 kB)_","public":true,...............} 

    The arguments to be passed with the request are: 

    1. "public": Whether the attachment should be public (visible on the portal for the customer) or not. The accepted values are true or false. Mandatory

    2. "temporaryAttachmentIds": The ID(s) of the temporary file(s) received in the response(s) to the previous request(s)

    3. "additionalComment" : {"body": ".........."}: In case you want to add a comment you can add a string as the comment body. Otherwise you can just avoid using this block. This is not mandatory. 

For further details please see:

Another way to add attachments to Service Desk issues is to use the JIRA Core REST API endpoint as explained in the below KB:

Last modified on Jun 17, 2019

Was this helpful?

Provide feedback about this article
Powered by Confluence and Scroll Viewport.