How to download attachments using REST API and SSO
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
Please Note: This article describes a proof-of-concept (POC) mechanism to download attachments from Jira through REST APIs. However, it's important to note that Jira is not meant to behave like a file server. Downloading issue attachments through REST APIs is not a supported use case for the application. We'd suggest considering the information in this article for informational purposes only.
Problem
When retrieving Jira information through REST API and SSO authentication, especially when both Jira and SSO are external and in different locations, some data may not be available with direct calls, such as attachments. In scenarios like this, the REST API lands at the SSO login page, not returning the expected data, and the alternative can be using cookies for authentication.
Here we are using SSO and PAT (personal access token).
Solution
The solution for scenarios as this is storing cookies and later using them in the call. As below:
Use a first call to store the cookie in a file
1
curl -H "Authorization: Bearer xxxxx" -X GET <rest endpoint url> --cookie-jar ./storedcookie
Then in a second call, the attachment download however using the cookie
1
curl -L -H "Authorization: Bearer xxxxxx" <attachment rest endpoint url> --output test.png --cookie ./storedcookie
Example

Read more
Was this helpful?