Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Uploading an attachment via API doesn't work but gives Status 200

Alessio Nicolo Perna January 26, 2022

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"'


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?

 

2 answers

1 accepted

1 vote
Answer accepted
Alessio Nicolo Perna January 26, 2022

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 

Pramodh M
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 26, 2022

Yeah Right!!

You should use Base URL to mitigate errors

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

Like Alessio Nicolo Perna likes this
1 vote
Pramodh M
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 26, 2022

Hi @Alessio Nicolo Perna 

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

Pramodh M
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 26, 2022
Alessio Nicolo Perna January 26, 2022

Hey @Pramodh M ,

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

Pramodh M
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 26, 2022

@Alessio Nicolo Perna 

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

Alessio Nicolo Perna January 26, 2022

yes, everything else apart from uploading attachments works. Even updating contents on the page works.

Varun.Ravindranath2 August 1, 2023

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?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events