Uploading an attachment via API doesn't work but gives Status 200
Asked by Alessio Nicolo Perna:

Hey everyone,

so I am currently working on an internal tool for our company that automatically uploads an attachment onto our company's confluence (Version 6.14.3) via REST API. Updating content on a page works without any issues but uploading any sort of attachment doesn't do anything for some reason and I want to know why.

To be precise:

When sending the following request via curl

```
curl --location --request POST 'http://my.companies.confluence.com/rest/api/content/1234567/child/attachment' \

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

--header 'Authorization: Basic placeholdercredentials' \

--form 'file=@"foobar.pdf"' \

--form 'comment="This is a test"'
```

<br />

I get a response with the status 200, which should mean it was successful but when looking on the actual attachments of the page in the browser, the newly uploaded one is not included. Apart from that the body of the response just shows the currently available attachments instead of the newly uploaded one.

And here comes the tricky part now. I have been trying practically the same request on a mock up Confluence docker container with similar prerequisites and a similar version (6.15.5) and it worked with no issues whatsoever. I even tried it with a "generic" user that has basic access and is in the confluence-user group and it still worked.

According to the admins of our company's confluence the user has all the necessary permissions, which can't be right in my opinion, but then again I don't really know why the api would send me such a faulty response then?


Answers:
author: Alessio Nicolo Perna
body: For anyone having this issue, I have found the answer myself.

Turns out our company's confluence only allows POST-Requests via HTTPS, which kind of makes sense since transmitting files through a secured connection is safe.

I presume it depends on how they configure their confluence or generally speaking whether they have a certificate but yeah, it just worked with https instead of http.

So instead of

```
http://my.companies.confluence.com/rest/api/content/1234567/child/attachment
```

I used

```
https://my.companies.confluence.com/rest/api/content/1234567/child/attachment
```

for POST requests

comments: author: Pramodh M
body: Yeah Right!!

You should use Base URL to mitigate errors

It will still work if you use http with -k option in place!!


author: Pramodh M
body: Hi [@Alessio Nicolo Perna](/t5/user/viewprofilepage/user-id/4087859)

Use the below API

    curl -u username:password \ -X POST your-confluence-base-url/rest/api/content/${PAGE_ID}/child/attachment\ -H "X-Atlassian-Token: nocheck" -F "file=@ATTACHMENT_FILE_NAME" -F "comment=File attached via REST API"

Try with Basic Username and Password Authentication!!

Let me know if it works for you

Thanks,  
Pramodh

comments: author: Pramodh M
body: Reference here

<https://confluence.atlassian.com/confkb/using-the-confluence-rest-api-to-upload-an-attachment-to-one-or-more-pages-1014274390.html>


author: Alessio Nicolo Perna
body: Hey [@Pramodh M](/t5/user/viewprofilepage/user-id/3691224) ,

thanks but unfortunately, it didn't work. It returns the same response with status 200 but no sign of the new attachment being uploaded.


author: Pramodh M
body: [@Alessio Nicolo Perna](/t5/user/viewprofilepage/user-id/4087859)

Are you able to use the GET Page API correctly, are other APIs are working fine?


author: Alessio Nicolo Perna
body: yes, everything else apart from uploading attachments works. Even updating contents on the page works.


author: Varun.Ravindranath2
body: The attachment upload never works it throws page unavailable when we follow the same as listed in the solution. Any possible issue resolution.

Anybody who is able to upload attachments via rest api?


Tags: attachment

confluence-server

error

rest-api

server