I am trying to upload a Excel document (.xls) file to a page within my space in confluence via the Cloud Rest API. However, we are not trying to upload it as an attachment. We want the file to be uploaded to the page itself.
The following command uploads it to the page as an attachment:
curl.exe -v -S -u username:password -X POST -H "X-Atlassian-Token: no-check;" "file=@<path to file>" "https://<environment>/wiki/rest/api/content/<page>/child/attachment"
This is not what we want. Below is a picture of a page with the file upload manually. This is what we are looking for via the rest API.
This is what we are getting from the above command:
They get attached to the attachments.
Using the Confluence API is a great way to automate tasks and make repetitive tasks less time consuming. It seems as though you have a solid understand of how to interact with the API.
With this said, the API endpoint you’re using is specifically for attaching a file to a parent page. This would cause a file to be a child of the parent adding it to the attachments page (not the page itself).
What you’re needing to do is to update the contents of the page itself after the file has been attached. This will not be accomplishable through a single endpoint, you will require at least 3 endpoints to complete this task. Here are the endpoints in the order you must use them:
In this order, you will need to PUT the attachment. From there you will need to get the content of the page you want to update. Once you have the page you need to update you will then PUT the new content (using the storage format) of the page back into Confluence to include the storage format of the attachment you wish.
Here if further information on the Confluence page storage format: Confluence Storage Format (For server but will apply to cloud).
The above will allow you to attach a file to a page and then update said page with placing the attachment within using the storage format. If you run into any issues moving forward, please let us know so we may help you accomplish your goal.
Wherever you are in your team’s journey , our goal is to support your big ambitions. We’re a cloud-first company with the mission of unleashing the potential of every team, and to address the range ...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events