How to add an attachment to Jira Cloud work items using the REST API
Platform Notice: Cloud Only - This article only applies to Atlassian apps on the cloud platform.
Summary
This article covers adding attachments to a Jira work item via the REST API endpoint.
Solution
Option 1: Using the command line:
curl --location --request POST 'https://your-domain.atlassian.net/rest/api/3/issue/TEST-123/attachments'
-u 'email@example.com:<api_token>'
-H 'X-Atlassian-Token: no-check'
--form 'file=@"myfile.txt"'
Option 2: Using GUI-based tools (Postman)
This can also be achieved using any GUI tools of your preference. Here is an example of how to perform the same operation using the POSTMAN tool.
Ensure to include Content-Type and X-Atlassian-Token under the Headers tab with the shared values.
Content-Type = multipart/form-data
X-Atlassian-Token = no-check
Ensure that you include a key named file and type File to select a file from the system, or Text to access files using absolute path/reference under the Body tab.
When adding attachments via the REST API endpoint to a Jira work item, if the payload or body isn't formatted well, the following error is thrown: 415 Unsupported Media Type.
Keep in mind the permission limitations that might be associated with the file based on its location on the local machine.
Was this helpful?