Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to use RESTfull PUT to update a page? Edited

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

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

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Confluence

What do you think is the most *delightful* Confluence feature? Comment for a prize!

- Create your own custom emoji 🔥 - "Shake for Feedback" on mobile 📱 - An endless supply of GIFs via GIPHY 🤩 Is there anything quite as nice as a pleasant surprise? Comment below with what...

402 views 23 8
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you