How to copy the newest attachment to a linked software issue?
Asked by Iker G?mez Eiras:

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.


Answers:
author: Eugenio Onofre
body: Hi [@Iker G?mez Eiras](/t5/user/viewprofilepage/user-id/4999010)

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

comments: author: Iker G?mez Eiras
body: 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)](https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issue-attachments/#api-rest-api-2-attachment-id-get) \<\<-- this is what the listener has available.


author: Eugenio Onofre
body: [@Iker G?mez Eiras](/t5/user/viewprofilepage/user-id/4999010) 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?


author: Iker G?mez Eiras
body: [@Eugenio Onofre](/t5/user/viewprofilepage/user-id/4992586)

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.


Tags: attachment

cloud

jira-cloud

jira-service-management

jira-service-management-cloud

jira-software-cloud