How to Export Attachments from Jira Cloud Projects via REST API
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
This article provides a step-by-step guide on how to export all attachments from a single project in Jira Cloud by leveraging the Jira REST API. You can perform this method directly through API calls.
Diagnosis
You need to download all attachments from work items within a specific project in Jira Cloud. Accomplish this task by using the Jira REST API.
Cause
There is no direct functionality in Jira Cloud's UI to export all attachments from a project. However, the REST API provides a way to retrieve and download these attachments programmatically.
Solution
Generate an API Token
Visit Atlassian's API token management page to generate an API token. Use this token for authentication purposes.
Prepare the API Request to get all Work Items with Attachments
Permissions required - ensure that you have:
Browse projects permission for the project containing the work item.
Work-item-level security permission if it is configured.
Make a POST request to the Jira REST API to search for work items with attachments. Use the following endpoint and payload:
POST https://<your-domain>.atlassian.net/rest/api/3/search { "jql": "project = <your-project-key> AND NOT attachments is EMPTY", "startAt": 0, "maxResults": 100, "fields": ["attachment"], "fieldsByKeys": false }
Replace
<your-domain>
with your Jira Cloud domain and<your-project-key>
with your project's key.
Make the API Request
Use tools like Postman, which provides a user-friendly interface, or
curl
in the terminal for more advanced users. These tools are widely used and can help you execute API calls effectively.Here is an example using
curl
:curl -sL --request POST \ --user "email@example.com:your-api-token" \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --url "https://<your-domain>.atlassian.net/rest/api/3/search" \ --data '{ "jql": "project = <your-project-key> AND NOT attachments is EMPTY", "startAt": 0, "maxResults": 100, "fields": ["attachment"], "fieldsByKeys": false }'
The command returns a JSON response with work items that have attachments.
Parse the JSON Response to Extract Attachment URLs
If using a command-line tool use a tool like `jq` to easily extract the attachment URLs from the JSON response along with their corresponding work item keys.
Here’s a sample command to achieve this:
curl -sL --request POST \ --user "email@example.com:your-api-token" \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --url "https://<your-domain>.atlassian.net/rest/api/3/search" \ --data '{ "jql": "project = <your-project-key> AND NOT attachments is EMPTY", "startAt": 0, "maxResults": 100, "fields": ["attachment"], "fieldsByKeys": false }' \ | jq -r '.issues[] | {key,attachment:.fields.attachment[]} | [.key, .attachment.content, .attachment.filename] | join(" ")'
This command will output lines containing the work item key, attachment URL, and filename for each attachment.
Download the Attachments
Download the attachments with the attachment URLs using another
curl
command or a similar tool.Here’s an example
curl
command to download an attachment:curl -L --create-dirs --user "email@example.com:your-api-token" --url "<attachment-url>" --output "<issue-key>/<filename>"
Conclusion
By following these steps, you can efficiently export all attachments from a specific project in Jira Cloud using the REST API.
References
Was this helpful?