How to use RESTfull PUT to update a page?

csmith October 30, 2019

I can create the page with a command like:

curl -D- -u 'U:P' -X POST -H "Content-Type: application/json" -d @DOC.json "https://url/wiki/rest/api/content?title=Test+Doc&spaceKey=MD"

 

This works! And the doc is created. Then I goto the page in a browser and get it id?

https://url/wiki/spaces/MD/pages/4784186/Test+Doc

 

Then I use a GET to get the data using the id 4784186

curl -D- -u 'U:P' -X GET -H "Content-Type: application/json" https://url/wiki/rest/api/content/4784186

 

And I get info about the page:

{"id":"4784186","type":"page","status":"current","title":"Test Doc","space":{"id":196609,"key":"MD","name":"xxxxx","type":"global","status":"current","_expandable":{"settings":"/rest/api/space/MD/settings","metadata":"","operations":"","lookAndFeel":"/rest/api/settings/lookandfeel?spaceKey=MD","permissions":"","icon":"","description":"","theme":"/rest/api/space/MD/theme","history":"","homepage":"/rest/api/content/196610"},"_links":{"webui":"/spaces/MD","self":"https://.../wiki/rest/api/space/MD"}},"history":{"latest":true,"createdBy":{"type":"known","accountId":"5d9b7a4af8c67f0dbff6b290","accountType":"atlassian","email":"u@comp.com","publicName":"user","profilePicture":{"path":"/wiki/aa-avatar/5d9b7a4af8c67f0dbff6b290","width":48,"height":48,"isDefault":false},"displayName":"Craig Smith","_expandable":{"operations":"","personalSpace":""},"_links":{"self":"https://.../wiki/rest/api/user?accountId=5d9b7a4af8c67f0dbff6b290"}},"createdDate":"2019-10-29T20:38:35.616Z","_expandable":{"lastUpdated":"","previousVersion":"","contributors":"","nextVersion":""},"_links":{"self":"https://.../wiki/rest/api/content/4784186/history"}},"version":{"by":{"type":"known","accountId":"5d9b7a4af8c67f0dbff6b290","accountType":"atlassian","email":"user@comp.com","publicName":"name","profilePicture":{"path":"/wiki/aa-avatar/5d9b7a4af8c67f0dbff6b290","width":48,"height":48,"isDefault":false},"displayName":"Craig Smith","_expandable":{"operations":"","personalSpace":""},"_links":{"self":"https://.../wiki/rest/api/user?accountId=5d9b7a4af8c67f0dbff6b290"}},"when":"2019-10-29T20:38:35.616Z","friendlyWhen":"yesterday at 4:38 PM","message":"","number":1,"minorEdit":false,"syncRev":"0.confluence$content$4784186.2","syncRevSource":"synchrony-ack","confRev":"confluence$content$4784186.5","_expandable":{"collaborators":"","content":"/rest/api/content/4784186"},"_links":{"self":"https://.../wiki/rest/api/content/4784186/version/1"}},"macroRenderedOutput":{},"extensions":{"position":1872770356},"_expandable":{"childTypes":"","container":"/rest/api/space/MD","metadata":"","operations":"","children":"/rest/api/content/4784186/child","restrictions":"/rest/api/content/4784186/restriction/byOperation","ancestors":"","body":"","descendants":"/rest/api/content/4784186/descendant"},"_links":{"editui":"/pages/resumedraft.action?draftId=4784186","webui":"/spaces/MD/pages/4784186/Test+Doc","context":"/wiki","self":"https:/.../wiki/rest/api/content/4784186","tinyui":"/x/OgBJ","collection":"/rest/api/content","base":"https://.../wiki"}}

 

Then I try a PUT:

curl -D- -u 'U:P' -X PUT -H "Content-Type: application/json" -d @Text.json "https://.../wiki/rest/api/content/4784186

 

I get a HTTP 400 response:

HTTP/2 400 

server: AtlassianProxy/1.15.8.1

cache-control: no-cache, no-store, must-revalidate

content-type: application/json

strict-transport-security: max-age=315360000; includeSubDomains; preload

date: Wed, 30 Oct 2019 14:31:29 GMT

atl-traceid: 6906da9b9b242901

expires: Thu, 01 Jan 1970 00:00:00 GMT

x-xss-protection: 1; mode=block

x-content-type-options: nosniff

atl-confluence-via: h:confluence-prod-us-7-3.prod.atl-paas.net

 

{"statusCode":400,"data":{"authorized":false,"valid":true,"errors":[],"successful":false},"message":"com.atlassian.confluence.api.service.exceptions.BadRequestException: content id mismatch"}

 

With the only detail message":"com.atlassian.confluence.api.service.exceptions.BadRequestException: content id mismatch"

 

Any ideas on what I am doing wrong. Any ideas on what to try?

 

Another try using the doc name:

curl -D- -u 'U:P' -X PUT -H "Content-Type: application/json" -d @Test.json "https://.../wiki/rest/api/content?title=Test+Doc&spaceKey=MD"

 

HTTP/2 400 

server: AtlassianProxy/1.15.8.1

cache-control: no-cache, no-store, must-revalidate

content-type: application/json

strict-transport-security: max-age=315360000; includeSubDomains; preload

date: Wed, 30 Oct 2019 14:37:25 GMT

atl-traceid: 0a2d9bad15d046ac

expires: Thu, 01 Jan 1970 00:00:00 GMT

x-xss-protection: 1; mode=block

x-content-type-options: nosniff

atl-confluence-via: h:confluence-prod-us-7-3.prod.atl-paas.net

 

{"statusCode":400,"data":{"authorized":false,"valid":true,"errors":[],"successful":false},"message":"com.atlassian.confluence.api.service.exceptions.BadRequestException: content id mismatch"}Craigs-MacBook-Pro:tmp csmith$ 

Craigs-MacBook-Pro:tmp csmith$ 

Craigs-MacBook-Pro:tmp csmith$ vi put_to_confluence.sh 

Craigs-MacBook-Pro:tmp csmith$ ./put_to_confluence.sh 

./put_to_confluence.sh: line 6: unexpected EOF while looking for matching `"'

./put_to_confluence.sh: line 8: syntax error: unexpected end of file

Craigs-MacBook-Pro:tmp csmith$ vi put_to_confluence.sh 

Craigs-MacBook-Pro:tmp csmith$ ./put_to_confluence.sh 

HTTP/2 405 

server: AtlassianProxy/1.15.8.1

content-type: application/octet-stream

strict-transport-security: max-age=315360000; includeSubDomains; preload

date: Wed, 30 Oct 2019 14:44:16 GMT

atl-traceid: f866e40a3b5f49b6

x-xss-protection: 1; mode=block

x-content-type-options: nosniff

atl-confluence-via: h:confluence-prod-us-7-3.prod.atl-paas.net

allow: HEAD,POST,GET,OPTIONS

content-length: 0

 

1 answer

1 accepted

0 votes
Answer accepted
Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 31, 2019

Hello!

Thanks for including your multiple curl attempts and the output from said attempts. From reviewing what you’ve included I do see you don’t have the version incremented from the original GET call. With this said, you’ll need to increment the version number +1 from your GET call since a PUT method will create a new version. Further information on this is listed within the REST API docs;

version REQUIRED

object

The new version for the updated content. Set this to the current version number incremented by one, unless you are changing the status to 'draft' which must have a version number of 1.

Source documentation: PUT /wiki/rest/api/content/{id}

Please let us know if this helps to get past your response of 400.

Regards,
Stephen SIfers

csmith October 31, 2019

Thanks Stephen! Yes, I kept at it and found that I needed to bump the version number to get the PUTs to work. Now I an working out a way to curl to the the current version number so I can bump it and use the next version number in the PUT.

 

Thanks again for the reply!

Like Stephen Sifers likes this
Pradeep Tidke
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!
September 17, 2021

I am using simple update_page function. still Im getting error:

atlassian.errors.ApiValueError: No space or no content type, or setup a wrong version type set to content, or status param is not draft and status content is current.

 

How to solve this?

Please help

run ruan
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!
April 7, 2023

you need escape body content when update_page

Sheldon Cheng
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!
May 14, 2024

Hi, I am getting the same Api error:

requests.exceptions.HTTPError: com.atlassian.confluence.api.service.exceptions.BadRequestException: Content body cannot be converted to new editor format

 

atlassian.errors.ApiValueError: No space or no content type, or setup a wrong version type set to content, or status param is not draft and status content is current.

 

I tried using the suggestion

 

from html import escape

status = conf.update_page(
page_id,
page_title,
escape(body),
parent_id=None,
type='page',
representation='storage',
minor_edit=False
)

when I do this, my page no longer shows up as HTML but it shows the raw HTML code. What am I missing?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events