Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to copy the newest attachment to a linked software issue?

Iker Gómez Eiras
Contributor
January 9, 2024

This all in Cloud.

We have ITSM and software issues linked, on occassion.
When that happens, if a new attachment is added to the ITSM ticket, I need to copy it to the software ticket.
Only that one. Only the new one. And I can NOT delete the attachments that already exist in software.

I've been looking around, and people say you can get a download URL from the rest api using scriptrunner, then use the data you can get from that URL to create the attachment in the other ticket also via API.

Problem is, none of these seem possible?
When I grab attachment data via rest api, I don't get the URL to the attachment, or the content in binary/raw form. I get a crapload of metadata, but that's about it.

Also, if my listener script is triggered by the attachment creation, I can't see how I can get issue data, so I can look for the linked issues, to know where to copy it. It's not directly available and I can't seem to get it from the attachment metadata.

I'm honestly out of ideas here. Please help.

1 answer

0 votes
Eugenio Onofre
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 12, 2024

Hi @Iker Gómez Eiras

This may be achieved by using Script Runner and custom development:

You need to set up an event listener in ScriptRunner that triggers on attachment creation. This listener should be able to capture the event and extract relevant data, such as the ID of the issue to which the attachment was added.

Once the listener is triggered, use the issue ID to fetch the issue data. This includes details about linked issues. Use Jira's REST API to get information about the linked issues. The API endpoint /rest/api/3/issue/{issueIdOrKey} can be used to retrieve this data. The REST API call to the issue will include metadata about attachments, including their IDs. 

The metadata includes a URL for each attachment. This URL is what you need to download the attachment. It's usually in the format /secure/attachment/{attachmentId}/{filename}. 

Write a script to download the attachment using the URL obtained. You'll need to make an authenticated request to this URL to get the binary content of the attachment. Use the REST API endpoint /rest/api/3/issue/{issueIdOrKey}/attachments to upload the attachment to the linked issue.

Please remember to accept this answer in case it helps you resolve your question as it may also help other community members in the future.

Regards,
Eugenio

Iker Gómez Eiras
Contributor
January 15, 2024

Thanks for your reply, but no -- I already tried with a listener running on the "Attachment created" event, but that does NOT have the ticket data available -- no ID or Key or anything.

The Jira Cloud platform REST API (atlassian.com) <<-- this is what the listener has available.

Eugenio Onofre
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 15, 2024

@Iker Gómez Eiras I just tried myself and was able to retrieve the attachment data. Would you please confirm what are the endpoints you are using / post bodies?

Iker Gómez Eiras
Contributor
January 16, 2024

@Eugenio Onofre 

Attachment data, yes, it's issue data that gets lost -- the Attachment created event does NOT provide issue data, and I need both. The attachment, so I know what to copy, and the ticket data, so I can browse through its links to figure out the destination issue.

I've also opened a support request with the Atlassian partner that provides support for us, and so far radio silence -- I've a feeling there's no way to do what I want to do.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events