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?
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
Yeah Right!!
You should use Base URL to mitigate errors
It will still work if you use http with -k option in place!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you able to use the GET Page API correctly, are other APIs are working fine?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes, everything else apart from uploading attachments works. Even updating contents on the page works.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.