Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

update page confluence rest api bash

Adrian Jakubik
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 29, 2018

Hello,

i have the following code, which works perfectly in a /etc/init.d/ script:

curl -u USER:PASSWORD -X PUT -H 'Content-Type: application/json' -d '{"id":"1234567","type":"page","title":"mytitle","space":{"key":"example"},"body":{"storage":{"value":"<p>Someone just restarted Service on '$hostname': '$NOW'</p>","representation":"storage"}},"version":{"number":'$VERSION'}}' "https://mydomain.com/rest/api/content/1234567"

 After the script gets executed the confluence page updates the page correctly:

someone just restarted Service on XYZ: 2018-11-29_09:22:50

but if i run the script again it gets overwritten. I dont want to update the old content i want to post it as new line for example:

 

someone just restarted Service on XYZ: 2018-11-29_09:22:50

someone just restarted Service on XYZ: 2018-11-29_09:24:33

just to gather all restarts 

i tried to work with '\n' but i dont seem to work

 

https://docs.atlassian.com/ConfluenceServer/rest/6.12.2/#content-update

 

Regards

1 answer

0 votes
Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 30, 2018

Hello Adrian and welcome to the Community!

Your API is a perfect example and will update/overwrite the content on the page. The issue you are having is you are telling the REST API to replace ALL content on that page with new content as a new version. With this said, here are some steps to get a resolution to your issue.

  1. First make a GET request to the page and store the page contents (body storage value) as a variable.
  2. With the new variable, you will want to pass this through to your PUT request so your new values are appended to the first page.
  3. Your PUT request will not append the original content from the page along with the new content you have. You have to ensure the old content is passed through.

To simplify the answer, PUT requests will overwrite all content on the page. You will need to run a GET to store the content to pass through to the PUT request.

Here would be a simplified example with variables:

#Store this output as your OldContent variable
curl -u USER:PASSWORD  -X GET "https://mydomain.com/rest/api/content/60424376?title=WhoDoneIt&&limit=1&expand=body.storage

#This will be the content from your the page you want to update.
$OldContent = '<p>Stephen just restarted Service on XYZ: 2018-11-29_09:22:50</p>'

#Your request with passing the $OldContent through
curl -u USER:PASSWORD -X PUT -H 'Content-Type: application/json' -d '{"id":"1234567","type":"page","title":"mytitle","space":{"key":"example"},"body":{"storage":{"value":"'$OldContent' <p>Someone just restarted Service on '$hostname': '$NOW'</p>","representation":"storage"}},"version":{"number":'$VERSION'}}' "https://mydomain.com/rest/api/content/1234567"

In short, the REST API does not have an append function and will replace all content on the page until you pass the original content through.

I hope this clarifies how to get your old content onto your new version of page.

Regards,
Stephen Sifers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events