How can I automatically update a Confluence page via a script... rest api not working

I am trying to set up a script I have to send a specific type of file to a Confluence page I have set up.  I have tried to use the REST API information that is provided, but I am not sure if I am setting it up correctly.  For now I am just trying to use a curl command since the script I have is written in BASH.  


The specific page url looks like (nearly identical to) this: https://<my-company><9-digit-number-here>/Recent+Test+Results


My thought would be that I would need to use the "Upload an attachment" endpoint as seen here, but I am not sure if I am configuring it correctly.  Thoughts?  I have tried plugging in values for the different pieces of the endpoint url, but not sure if they are correct.  Thanks in advance

1 answer

1 accepted

Accepted Answer
2 votes
Anton Chemlev Community Champion Nov 14, 2017


Could you please provide some details:

1) What Confluence do you use: cloud or server? And version. Because you link looks like Cloud, but link to Confluence docs you provided is for Server version.

2) What does it mean - "not working"? Could you provide full curl command and error text?

3) What type and size of file are you trying to upload? Does it fit into system allowed Attachment maximum size? By default it is 100MB, but maybe you changed it.

Hi Anton,

  Thank you for replying.  To answer your questions:

1.) I wasn't sure at first if I was using Cloud or Server (had never really used this service before so couldn't really tell), but I've discovered that it is the Cloud.  I've since gone into that documentation and seen what I can use.... however, still unsure of how to proceed.

I am hoping to upload an attachment to a specific page that I created.  Upon looking through the documentation I believe that I should be trying this curl (from

curl -D- \
  -u admin:admin \
  -X POST \
  -H "X-Atlassian-Token: nocheck" \
  -F "file=@example.txt" \
  -F "minorEdit=true" \
  -F "comment=Example attachment comment" \

I tried uploading a simple txt file as an attachment, but still not sure if I am adding the correct values for the specific page.  I assume that the url should look something like this:

curl -D- \

-u <my-user-email>:<my-password> \


-H "X-Atlassian-Token: nocheck" \

-F "file=@<name of file to send>" \

-F "minorEdit=true" \

-F "comment=Trying this out" \<9-digit-number-which-I-assume-is-the-space-id>/child/attachment


When I submitted this in my terminal I got an error of:

(26) couldn't open file "firmware.txt"

I will continue to play around with this, but I'm a little confused about why the "@" needs to be before the filename, and if I am actually pointing to the correct place.  

The files that I am trying to upload ultimately are just simple PNG files, about 6911 bytes.  

To give you an example of what I had been getting prior to this most recent attempt, here is the curl command and the response I was getting before:

Curl command:

curl -v -S -u <username>:<password> POST -H "X-Atlassian-Token: no-check" -F "file=Lock_Firmware/CHART/EUROPA/EUROPA-1.7.8-2017-11-01-12-37-16.png" -F "comment=11/09/2017 EUROPA 1.7.7" "http://<myhost>/rest/api/content/211845263/child/attachment"



* Rebuilt URL to: POST/

* Could not resolve host: POST

* Closing connection 0

curl: (6) Could not resolve host: POST

*   Trying <my-host-ip>...


* Connected to <myhost>(<myhost-ip>) port 80 (#1)

* Server auth using Basic with user '<my-username>'

> POST /rest/api/content/211845263/child/attachment HTTP/1.1

> Host: <myhost>

> Authorization: Basic <some-hash>

> User-Agent: curl/7.54.0

> Accept: */*

> X-Atlassian-Token: no-check

> Content-Length: 321

> Expect: 100-continue

> Content-Type: multipart/form-data; boundary=------------------------2bda88f822a47675


* Done waiting for 100-continue

< HTTP/1.1 301 Moved Permanently

< Content-Type: text/html

< Date: Tue, 14 Nov 2017 21:32:06 GMT

< Location: https://<myhost>/rest/api/content/211845263/child/attachment

< Connection: Keep-Alive

< Content-Length: 0

* HTTP error before end of send, stop sending


* Closing connection 1

Anton Chemlev Community Champion Nov 20, 2017


1) About @ in curl:

--data-binary <data>
  (HTTP) This posts data exactly as specified with no extra processing whatsoever.
  If you start the data with the letter @, the rest should be a filename.  Data is
  posted in a similar manner as --data-ascii does, except that newlines are preserved
  and conversions are never done.

  If this option is used several times, the ones following the first will append data
  as described in -d, --data.

 2) (26) couldn't open file "firmware.txt" - try to use absolute file to path

3) It seems to me there's an error. URL should be in -X option as far as i know.

curl -D- \
  -u admin:admin \
  -X POST  http://myhost/rest/api/content/123/child/attachment \
  -H "X-Atlassian-Token: nocheck" \
  -F "file=@example.txt" \
  -F "minorEdit=true" \
  -F "comment=Example attachment comment"


  Hello again.  Thank you for that explanation, you've been most helpful.  I was able to figure out what I needed to do in order to successfully create an attachment.  It did not end up doing what I expected, but the attachments are in fact there and I can view them.  I was expecting the attachment (which in my case is a PNG file) to actually appear on the page as the image itself, and not just as a linked attachment in the attachments specific page that is linked to my content id.  

  In other words, I'm trying to just add an image to the page itself, not an attachment.  I'm unsure based on what I am seeing in the CLOUD REST API docs as to how I can do that.... all I seem to be able to do is add text (which is what a co-worker of mine was able to do on another Confluence page in our company's main space).  Any thoughts on how I could configure the Create Content endpoint to accept an image?

Thank you in advance


  Ok cool.  I will look into how that works and see if I can make something work.  I do appreciate your help, and I'm glad that I at very least am now able to successfully attach the image to the page correctly.  Cheers

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Monday in Jira Ops

Jira Ops Early Access Program Update #1: Announcing our next feature and a new integration

Thanks for signing up for Jira Ops! I’m Matt Ryall, leader for the Jira Ops product team at Atlassian. Since this is a brand new product, we’ll be delivering improvements quickly and sharing updates...

491 views 0 9
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