How to download attachments using REST API and SSO

Still need help?

The Atlassian Community is here for you.

Ask the community


Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

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


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

    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

    curl -L -H "Authorization: Bearer xxxxxx" <attachment rest endpoint url> --output test.png --cookie ./storedcookie


Example

Read more


Last modified on Apr 17, 2024

Was this helpful?

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