Exporting All Attachments from a Single Project in Jira Cloud Using the REST API

Platform Notice: Cloud - This article 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. This method can be performed directly through API calls.

Environment

Jira

Diagnosis

You need to download all attachments from issues within a specific project in Jira Cloud. This task can be accomplished 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

  1. Generate an API Token

  2. Prepare the API Request to Retrieve Issues with Attachments

    • Permissions required: Issues are included in the response where the user has:

    • You will need to make a POST request to the Jira REST API to search for issues 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 the key of your project.  
  3. Make the API Request

    • You can use tools like Postman to make this request, or use curl in the terminal. 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
         }'
    • This command will return a JSON response containing the issues with attachments.
  4. Parse the JSON Response to Extract Attachment URLs - If using a command-line tool, you can parse the JSON response using `jq` to extract the attachment URLs and their corresponding issue 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 issue key, attachment URL, and filename for each attachment.
  5. Download the Attachments - Once you have the attachment URLs, you can download them 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>"

By following these steps, you can efficiently export all attachments from a specific project in Jira Cloud using the REST API.

References

  1. Basic auth for REST APIs
  2. Search for issues using JQL
  3. https://stedolan.github.io/jq/



Last modified on Aug 12, 2024

Was this helpful?

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