Developer Portal for YouTrack and Hub Help

Download an Issue Attachment

Use Case

Use the REST API to download an attachment of a specific issue.

Summary

To solve this task, you basically need to obtain a full download URl of a specific issue attachment. To do so:

  1. Get a list of available attachments with their attributes.

  2. Get the attachment by its returned URL.

Step-by-Step

Get the list of issue attachments

To get the list of issue attachments, send a GET request to the following endpoint:

/api/issues/{issue_ID}/attachments

To form a download URL for an attachment, make sure you specify the url attribute in the fields request parameters. To make the identification of the target attachment easier, add also the name attribute at least.

For example:

curl -X GET 'https://example.youtrack.cloud/api/issues/2-6/attachments?fields=name,size,mimeType,extension,charset,url' / -H 'Accept: application/json' / -H 'Authorization: Bearer {TOKEN}'
[ { "charset": null, "extension": "png", "url": "/youtrack/api/files/7-2?sign=MTYxMzE2OTAwMDAwMHwxLTF8Ny0yfHdrRzJCYzA2cnZEclFLUzBLWEp6NXZGNE5kczA5eGVIVUUw%0D%0AbF9BVHZ3V3MNCg%0D%0A&updated=1569436739288", "mimeType": "image/png", "name": "orphan-modules.png", "size": 208788, "$type": "IssueAttachment" }, { "charset": null, "extension": "png", "url": "/youtrack/api/files/7-3?sign=MTYxMzE2OTAwMDAwMHwxLTF8Ny0zfFMxNW12bkFfNmhWZTFrWjhGa3lNZmF4Umt2MmFXWU1UWUFu%0D%0AUDJhalhITHMNCg%0D%0A&updated=1554209920719", "mimeType": "image/png", "name": "older-versions.png", "size": 23812, "$type": "IssueAttachment" } ]

Get the list of issue attachments

Now all we need to do is to follow the link that we've received in the url attribute of the attachment and save the result as a file.

Make a request in the following format:

curl -X GET --output picture.png 'https://{HOST:PORT}{URL from previous request}' -H 'Cache-Control: no-cache'

For example:

curl -X GET --output orphan-modules.png \ 'https://example.youtrack.cloud/api/files/7-2?sign=MTYxMzE2OTAwMDAwMHwxLTF8Ny0yfHdrRzJCYzA2cnZEclFLUzBLWEp6NXZGNE5kczA5eGVIVUUw%0D%0AbF9BVHZ3V3MNCg%0D%0A&updated=1569436739288' \ -H 'Cache-Control: no-cache'

Note that the Authorization header here is not required because the client is identified using the sign= request parameter.

Last modified: 19 April 2024