Issue creating attachments through REST API

Glenn Bousfield August 28, 2024

Hello, I am having an issue creating attachments for an existing issue using the REST API.

1. When I do a GET request to view my target issue, I am able to view the issue.

Request

curl --request GET --user <email:api-key> --header 'Accept:application/json' <organization domain>/rest/api/3/issue/{id}?fields=summary

Response

{"expand":"renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations","id":"{id}","self":"<organization domain>/rest/api/3/issue/{id}","key":"{key}","fields":{"summary":"Target for attachments"}}

2. When I do a GET request to view my permission to create attachments, I see that I have permission to create attachments.

Request

curl --request GET --url <organization domain>/rest/api/3/mypermissions?permissions=CREATE_ATTACHMENTS --user <email:api-key> --header 'Accept:application/json'

Response

{"permissions":{"CREATE_ATTACHMENTS":{"id":"19","key":"CREATE_ATTACHMENTS","name":"Create Attachments","type":"PROJECT","description":"Users with this permission may create attachments.","havePermission":true}}}

Based on these two requests, I expected that I would be able to create an attachment for the relevant issue.

However: When I create a POST request to create an attachment, the response tells me that I can't access the issue.

Request

curl --location --request POST <organization domain>/rest/api/3/issue/{issue}/attachments --user <email:api-key> --header X-Atlassian-Token:nocheck --form file=@"<path>\Test.txt"

 Response

{"errorMessages":["Issue does not exist or you do not have permission to see it."],"errors":{}}

 

Does anyone know what's happening here? I don't understand how to approach this issue. Thank you in advance for your help.

1 answer

1 accepted

0 votes
Answer accepted
Pears Whims
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 1, 2024

Hi @Glenn Bousfield ,

 

You seem to be on the right track. The API syntax you’re using is mostly correct, but there are a few things to consider:

  • If you’re able to upload files from the browser, it suggests that your permissions and API endpoint are set up correctly.
  • The issue might be related to the syntax or the environment where you’re running the script.

Syntax Check

Double-check the syntax, especially the header and file path. Consider adding quotes around the header like this:

--header 'X-Atlassian-Token: no-check'

Also for the simplicity consider running the script from the same directory where the attachment is located. This will allow to ensure that there is no issues with regard to path of the file.

file=@"Test.txt"

 

Atlassian documentation offers code snippets in various languages. Consider giving it a shot with some different approach on language You are familiar with, to isolate terminal/escaping issues

https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-rest-api-3-issue-issueidorkey-attachments-post

 

Cheers, mate. Happens to the best of us.

Glenn Bousfield September 2, 2024

Hi Pears,

Thanks for the helpful response.

I tried changing the syntax a few different ways and then at some point it worked. I am not sure what specifically needed to be fixed but now it works.

Cheers,

Glenn

Like Pears Whims likes this
Pears Whims
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 2, 2024

That's awesome. Thanks for the update, Glenn!

Suggest an answer

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

Atlassian Community Events