Issue creating attachments through REST API
Asked by Glenn Bousfield:

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 {#toc-hId-352373943}

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

#### Response {#toc-hId--1455080520}

```
{"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 {#toc-hId-1032432313}

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

#### Response {#toc-hId--775022150}

```
{"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 {#toc-hId-1712490683}

```
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 {#toc-hId--94963780}

```
{"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.


Answers:
author: Pears Whims
body: Hi [@Glenn Bousfield](/t5/user/viewprofilepage/user-id/5574169) ,

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.

comments: author: Glenn Bousfield
body: 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


author: Pears Whims
body: That's awesome. Thanks for the update, Glenn!


Tags: atlassian-accounts

attachments

cloud

jira-cloud

not-applicable

permissions

rest-api