How to download Jira attachments with Connect app user account?

It appears that Jira Cloud apps cannot download file attachments.

The REST API method GET /rest/api/3/attachment/{id} returns the metadata of the attachment, not the file itself. Its JSON response includes a link to download the attachment, but the link is in form of “…/jira/secure/…”, which cannot be accessed by the Connect app.

Example:
“content”: “https://your-domain.atlassian.net/jira/secure/attachments/10000/picture.jpg

How a Connect app can download the content of a Jira attachment?

Thanks!

Hi @danut.manda,

Apps can make GET requests to attachment URLs. Jira will respond with the attachment data.

Regards,
Dugald

Hi @dmorrow, thanks for your response.

We are issuing a GET request from java code using JWT authentication but the server returns 401 - Unauthorized.

We checked the URL with the token using the JWT decoder and it seems to be OK.

We will continue our investigation to see what might cause the access problem.

Hi @TeodorBaciu,

I ran a quick test and was able to download the content of a text file attachment. I wonder if there are any extra permission restrictions being applied in your case.

I’ve also created https://ecosystem.atlassian.net/browse/ACJIRA-2209 because the API for downloading an attachment is not sufficiently documented.

Regards,
Dugald

Hi @dmorrow,

after further investigation we can confirm that attachments are accessible using JWT authentication.

The errors we encountered seem to be caused by the url encoding of spaces in the filename of the attachments.

Expanding the documentation would be indeed very helpful to developers.

When we saw the 401 - Unauthorized errors, we thought that there is maybe a system restriction that requires a session with an authenticated user, since the URLs for the contents of the attachments are not in the “/rest/api/” namespace but in “/secure”. Thus one might think that accessing the contents is not part of the REST API available for Connect addons.

1 Like

Hi @TeodorBaciu,

Thanks for circling back. Hopefully the Jira team will improve the documentation under ACJIRA-2209.

Regards,
Dugald