cloud rest api Update content 400 error

정현수 February 24, 2021

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
Shannon S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 1, 2021

Hi @정현수,

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
AUG Leaders

Atlassian Community Events