Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Upload/Update attachment on Confluence page via rest api

Llyr Jones
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 12, 2023

When I run requests against this endpoint:

"https://your-domain.atlassian.net/wiki/rest/api/content/{id}/child/attachment"

I get various errors (403 for PUT and 500 for POST).

Can we have a working example for using this endpoint to upload a file to a confluence page please. E.g Upload `example.txt`.

Ideally Python but cURL should be fine either.

I am able to run get requests against the same endpoint and successfully return attachments, so I don't think there's an issue with my API key or permissions.

For context, I created the page and am able to edit it through my browser.

1 answer

0 votes
Vamsi Kandala
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.
January 12, 2023

Hi @Llyr Jones

Welcome to the community!

Ideally, it should be POST method. 

It could be that the REST API could not find the file that is being attached.  I have not tried it in Python but used third-party application like Postman.

If you don't mind, can you list the complete curl command here (after hiding your Confluence domain, of course).

Thanks,
Vamsi

Llyr Jones
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 12, 2023

Hi @Vamsi Kandala 

I'm using Postman but here is the cURL generated from my request

 

curl --location --request POST 'https://<Domain>/rest/api/content/<Page ID>/child/attachment' \
--header 'Authorization: Basic <API Key>' \
--header 'X-Atlassian-Token: nocheck' \
--form 'file=@"example.txt"' \
--form 'minorEdit="true"' \
--form 'comment="Example attachment comment"' \
--form 'type="text/plain"' \
--form 'charset="utf-8"'
Vamsi Kandala
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.
January 12, 2023

Hi @Llyr Jones

Is the attachment file in the same location from where you are executing this curl command?

Can you check this reference article: https://developer.atlassian.com/cloud/confluence/rest/v1/api-group-content---attachments/#api-wiki-rest-api-content-id-child-attachment-post and try out the example given?

Thanks,
Vamsi

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events