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
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.