Copy attachments from a projetc issue on cloudsite X to a project issue on cloudsite Y

Hi,

I want to copy all attachments from an issue on a project (site X) to an issue on a project on another site (Site Y) by using api on automation.
I don’t find how to specify content.

Automation
https://Site-Y.atlassian.net/rest/api/3/issue/MyIssueKey/attachements
call by POST method

Trying by :

{{#Issue.attachment}}
"file":"{{content}}"
{{/}}

and many others
But it’s not ok.

Can you help me please ?

Welcome to the Atlassian developer community @Souad,

Unfortunately, I don’t think Automation wasn’t designed for this scenario. Let’s have a closer look at the add attachment endpoint using POST /rest/api/3/issue/{issueIdOrKey}/attachments:

Adds one or more attachments to an issue. Attachments are posted as multipart/form-data (RFC 1867).

The Automation web request action was built for typical web hooks, which accept JSON, not multipart form encoded documents.

In theory (meaning, I haven’t tried this myself), the fields that Automation provides would allow for a very specific case where you know for sure what kind of attachment you have. For example, if your automation is always posting a CSV, you could write the data explicitly like so:

Content-Type: text/csv
Content-Disposition: form-data; name="table"; filename="table.csv"

file={{content}}
--BOUNDARY—

Then you must also set the following web request headers:

  • Content-Type: multipart/form-data; boundary=“BOUNDARY”
  • X-Atlassian-Token: no-check
  • Authentication: basic … (You’ll have to calculate the base64 encoding from your email address and your API token from your other site. Please note this is not recommended since base64 encoding is not “encryption” and this exposes your API token to other users. Unfortunately, there aren’t any other options for Automation at this time.)

Security implications aside, the problem with this approach is the assumption of the content type. If you have an image, a PDF, or any other media type, this would fail. In “high code” (the opposite of low code?), the program could do some extra work to inspect the content and adjust accordingly. Automation doesn’t have this. Perhaps the best solution would be a new kind of action appropriate for transferring attachments and would have knowledge of files & media types built-in. My recommendation is to open a feature request with Atlassian customer support.