Upload Excel document (.xls) to confluence page via Rest API

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.

image.png

This is what we are getting from the above command: 

image.pngThey get attached to the attachments.

 

2 answers

1 accepted

0 votes
Accepted answer

Hello Trevor,

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:

  1. PUT /wiki/rest/api/content/{id}/child/attachment
  2. GET /wiki/rest/api/content
  3. PUT /wiki/rest/api/content/{id}

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.

Regards,
Stephen Sifers

0 votes
Todd Ryan I'm New Here Wednesday

Hello, I have the same problem. HOWEVER, I am not automating the process. I just want to insert a living Excel sheet that when selected, just opens as an excel doc that can be edited and re saved.

 

Thanks

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Feb 06, 2019 in Confluence

Try out the new editing experience

Hi team, I’m Avinoam, a product manager on Confluence Cloud, and today I’m really excited to let the Community know that all customers can now try out the new editing experience and see some of the ...

1,016 views 51 8
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you