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

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

cloud rest api Update content 400 error

Hi, everyone.


I want to update content using rest api
document link = https://developer.atlassian.com/cloud/confluence/rest/api-group-content/#api-api-content-id-put

The code written based on the example is as follows.

HttpResponse<String> response = Unirest.get("https://xxx/wiki/rest/api/content/{id}?expand=body.storage,version,ancestors")

.basicAuth("user_id", "token")

.header("Accept", "application/json")

.asString();


JSONObject page = new JSONObject(response.getBody());

page.getJSONObject("body").getJSONObject("storage").put("value", "<p>hello, world<p>");



int currentVersion = page.getJSONObject("version").getInt("number");

page.getJSONObject("version").put("number", currentVersion + 1);



HttpResponse<String> put = Unirest.put("https://xxx/wiki/rest/api/content/{id}")

.basicAuth("user_id", "token")

.header("Accept", "application/json")

.header("Content-Type", "application/json")

.body(page)

.asString();



System.out.println(put.getBody());

return message

 {"statusCode":400,"data":{"authorized":false,"valid":true,"errors":[],"successful":false},"message":"com.atlassian.confluence.api.service.exceptions.BadRequestException: Must supply an incremented version when updating Content. No version supplied."}

 

1 answer

0 votes

Hi @epaqj,

I'm sorry you're running into issues here. I'm happy to help you with this.

The message that's returned means that you aren't using the right version number.

 {"statusCode":400,"data":{"authorized":false,"valid":true,"errors":[],"successful":false},"message":"com.atlassian.confluence.api.service.exceptions.BadRequestException: Must supply an incremented version when updating Content. No version supplied."}

 From the Confluence Cloud REST API page you linked, under Body Parameters

version

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.

To get the current version number, use Get content by ID and retrieve version.number.

It has to be incremented by 1, so if your current version is 1, then the next version is 2.  Retrieve your version number using the steps above, increment by 1, and see if that helps!

Take care,

Shannon

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
Community showcase
Published in Confluence

Confluence Mythbusters: Does Atlassian even use Confluence?

Hi, Confluence collaborators! As part of #Confluence-Collaboratory month, we’ve created a very special Mythsbusters segment, where we're dive into an interesting myth and uncover the truth behind i...

1,752 views 8 32
Read article

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