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

Trevor Schmidt January 15, 2019

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

1 vote
Answer accepted
Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 15, 2019

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

2 votes
Todd Ryan February 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
TAGS
AUG Leaders

Atlassian Community Events