How to know the attachment ID?

Jason Huang
Contributor
June 29, 2022

Hi,

I need to remove the specific attachment.

The attachment was uploaded to many issues.

There is a REST API to remove attachments (Jira 8.20.8 (atlassian.com) but it needs the ID of the attachment.

How can we get the ID of the attachment? And does each same attachment in different issues has the same ID?

3 answers

2 accepted

2 votes
Answer accepted
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 29, 2022

To get the ID of an attachment, you have to read the issue for its list of attached files.  /rest/api/2/issue/(issue key)?fields=attachment should do it.

Attachment ids are all unique, irrespective of the file content and name, you'll need to read every issue that has been affected.

1 vote
Answer accepted
Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 29, 2022
/rest/api/2/issue/<issue key>?fields=attachment

To list attachments as json.

Otherwise if you hover over attachment on view, it lists the ID in the url e.g.

/secure/attachment/2407901/myattachmentname.png

 

Attachments are unique to issues, and are stored for each issue in separate directory in the backend, with unique ids.

1 vote
Vijay Dadi
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 30, 2024

Hello,

 

I have the file name, how can i extract its attachment ID?

Frederick Brien September 11, 2024

Id also love to know! Bumping this comment.

Vijay Dadi
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 11, 2024

Hi @Frederick Brien 

You can get your attachment id with the web request https://xyz.atlassian.net/rest/api/3/issue/{{issue.key}}

{{webResponse.body.fields.attachment.id}} - This will give you all the attachment id's on the issue.

{{webResponse.body.fields.attachment.id.max}} - This will give you latest attachment id on the issue.

You can use the below web request to extract attachment using attachment id

https://xyz.atlassian.net/rest/api/3/issue/attachment/{{AttachmentID}}

 

Hope this helps !

Vijay

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.20.8
TAGS
AUG Leaders

Atlassian Community Events