It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
Answer accepted

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

1 vote
Todd Ryan I'm New Here Feb 13, 2019

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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published Thursday in Confluence

Confluence CVEs and common questions

Two vulnerabilities have been published for Confluence Server and Data Center recently: March 20, 2019 CVE-2019-3395 / CVE-2019-3396 April 17, 2019 CVE-2019-3398 The goal of this article is...

129 views 0 10
Read article

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