Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Bad Request when updating page using REST API editor v2

Victor Wolkers June 18, 2021 edited

Whenever I update a page, I get a Bad Request error, even though the page is successfully updated. My guess is that it has something to do with the metadata property for changing the editor version (which works as expected too). If I remove this editor metadata, I get no more errors.

What is it I'm missing? Is it the permission of the user? Is there something else that must be passed along with the editor metadata?

{"statusCode":400,"data":{"authorized":false,"valid":true,"errors":[],"successful":false},"message":"com.atlassian.confluence.api.service.exceptions.BadRequestException: Error occurred when updating content property editor. Cannot update content property.

PUT  /wiki/rest/api/content/{id} (omitting ids and such)

 {"title":"<title_omitted>","type":"page","space":{"key":"<key_omitted>"},"status":"current","container":{"id":"<id_omitted>","type":"page"},"ancestors":[{"id":"<id_omitted>"}],"body":{"storage":{"value":"<markdown_value_omitted>","representation":"wiki"}},"version":{"number":24},"metadata":{"properties":{"editor":{"value":"v2"}}}}

Response full error (omitting ids and such):

{"statusCode":400,"data":{"authorized":false,"valid":true,"errors":[],"successful":false},"message":"com.atlassian.confluence.api.service.exceptions.BadRequestException: Error occurred when updating content property editor. Cannot update content property. Property : JsonContentProperty{id='null', key='editor', content=ExpandedReference{idProperties={status=current, id=ContentId{id=<id_omitted>}, version=ExpandedReference{idProperties={number=24}, of=some(Version{by=null, when=null, message='null', number=24, syncRev='null', syncRevSource='null', ncsStepVersion='null', ncsStepVersionSource='null', confRev='null', content=EmptyReference{referentClass=class com.atlassian.confluence.api.model.content.Content}})}}, of=some(Content{id='ContentId{id=<id_omitted>}', type=page, title='<title_omitted>', status=current, space=ExpandedReference{idProperties={key=<key_omitted>}, of=some(Space{key='<key_omitted>', name='null'})}, history=EmptyReference{referentClass=class com.atlassian.confluence.api.model.content.History}, version=ExpandedReference{idProperties={number=24}, of=some(Version{by=null, when=null, message='null', number=24, syncRev='null', syncRevSource='null', ncsStepVersion='null', ncsStepVersionSource='null', confRev='null', content=EmptyReference{referentClass=class com.atlassian.confluence.api.model.content.Content}})}, ancestors=[Content{id='ContentId{id=<id_omitted>}', type=null, title='null', status=current, space=EmptyReference{referentClass=class com.atlassian.confluence.api.model.content.Space}, history=EmptyReference{referentClass=class com.atlassian.confluence.api.model.content.History}, version=EmptyReference{referentClass=class com.atlassian.confluence.api.model.content.Version}, ancestors=null (CollapsedList), container=EmptyReference{referentClass=interface com.atlassian.confluence.api.model.content.Container}, childTypes={}}], container=ExpandedReference{idProperties={}, of=some({id=<id_omitted>, type=page})}, childTypes={}})}, version=null} , isSuccessful: false, isAuthorized: true, isValid: false, hasErrors: true, Errors: \"jsonproperty.version.required\""}

 

2 answers

1 accepted

0 votes
Answer accepted
Victor Wolkers June 23, 2021

OK, I've got it now. Not exactly fixed, but working. So, I'm going to leave this here.

Lemme highlight that even though I get a bad request, my page is updated successfully. This is strange, but... Not a concern for me.

When creating or updating a page, I'm always sending this editor version in the metadata property. This is happens because of that jira issue you linked (CONFCLOUD-68057).

Now that I know this issue really exists, I've changed my program to pass the metadata only when creating, never when updating. This fixed my problem.

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 24, 2021

Thanks for sharing your findings @Victor Wolkers .

I believe this is a bug that needs further investigation. From a first search, the behavior looks similar to:

 

However, I will run some tests and in case I will proceed creating a new bug ticket for this issue.

I will share my findings in here.

 

Cheers,
Dario

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 24, 2021

@Victor Wolkers ,

I am actually not able to reproduce the issue even using the first format for the editor you were using.

This is the payload I have been sending:

{
"title":"Updated using rest api",
"type":"page",
"space":{
"key":"XXX"
},
"status":"current",
"body":{
"storage":{
"value":"<p>This is a page UPDATED using REST API</p><p>Link:&nbsp;&nbsp;<ac:link><ri:page ri:content-title=\"NEW TEST DE CAZ\" ri:version-at-save=\"6\" /></ac:link></p>",
"representation":"storage"
}
},
"version":{
"number":4
},
"metadata":{
"properties":{
"editor":{
"value":"v2"
}
}
}
}

 

As a response I get status code 200 followed by:

{"id":"63461XXXXX","type":"page","status":"current","title":"Updated using rest api","space":{"id":380XXXXXX,"key":"XXX","name":"xxxxx","type":"global","status":"current","_expandable":{"settings":"/rest/api/space/XXX/settings","metadata":"","operations":"","lookAndFeel":.......................

 

 

Now, one assumptions I can do (that will need to be verified) is that the editor property is not working well with wiki representation. 

Would it be an option to try to use storage format when passing the editor property and see if this works?

 

Another thing I noticed, the error message on your side is about not being able to update the content property editor:

Error occurred when updating content property editor. Cannot update content property

 

Can you kindly check (using the Get content by ID REST API endpoint) if the page is currently set to use editor v1 and this is why you get the error? 

 

 

Cheers,
Dario

Victor Wolkers June 24, 2021

Strangely, I was not able to reproduce the error again. I changed the representation to "storage" and it updated successfully.

Then, I changed the program to send the metadata even when updated and it updated successfully. I even rolled back to the json without the "key" property and it updated successfully. Then, in a desperate attempt to reproduce the error, I created a new page with the "wrong" metadata and tried to update it. Everything worked.

My only guess now is that something was fixed in between tests.

Like • Dario B likes this
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 24, 2021

I can see that a fix for the REST API endpoint to copy pages has been released this week and maybe there was a code-change that fixed this issue as well.  That's my only guess too :) 

Like • Victor Wolkers likes this
1 vote
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 22, 2021

Hello @Victor Wolkers ,

Welcome to the Atlassian Community!

If I understand correctly you are updating Confluence pages using REST API and this is failing if you also add the editor property returning error 400. However everything works fine if you omit this property. Is this correct?

Now, if my understanding is correct, can you kindly confirm which one of the 2 endpoints are you using?

  1.  Update content (PUT /wiki/rest/api/content/{id})
  2. Convert content body (POST /wiki/rest/api/contentbody/convert/{to})

 

Also, looking at the workaround for CONFCLOUD-68057 (Creating a page via API doesn't load the New Editing Experience) I can see that the syntax specified in there is the following:

"metadata":{
"properties":{
"editor":{
"key":"editor",
"value":"v2"
}
}
}

 

While the syntax in your request is:

"metadata":{
   "properties":{
      "editor":{
         "value":"v2"
      }
   }
}

 

Can you kindly try to add the "key":"editor" part to your request body and see if this works?

 

 

Cheers,
Dario

Victor Wolkers June 23, 2021 edited

Thank you for your reply, @Dario B.

First of all, yes, you are correct on all of your assumptions. I'm sorry that I made a mistake and wrote "POST" instead of "PUT". I am updating a content, not converting a content body. I will update my question to correctly point that out.

Secondly and sadly, your solution did not work. I get the same bad request result as follows:

 

PUT /wiki/rest/api/content/{id}

{"title":"{title_omitted}","type":"page","space":{"key":"{space_omitted"},"status":"current","container":{"id":"{id_omitted}","type":"page"},"ancestors":[{"id":"{id_omitted}"}],"body":{"storage":{"value":"{value_omitted}","representation":"wiki"}},"version":{"number":3},"metadata":{"properties":{"editor":{"key":"editor","value":"v2"}}}}

 

Response

{"statusCode":400,"data":{"authorized":false,"valid":true,"errors":[],"successful":false},"message":"com.atlassian.confluence.api.service.exceptions.BadRequestException: Error occurred when updating content property editor. Cannot update content property. Property : JsonContentProperty{id='null', key='editor', content=ExpandedReference{idProperties={id=ContentId{id={id_omitted}}, status=current, version=ExpandedReference{idProperties={number=3}, of=some(Version{by=null, when=null, message='null', number=3, syncRev='null', syncRevSource='null', ncsStepVersion='null', ncsStepVersionSource='null', confRev='null', content=EmptyReference{referentClass=class com.atlassian.confluence.api.model.content.Content}})}}, of=some(Content{id='ContentId{id={id_omitted}}', type=page, title='{title_omitted}', status=current, space=ExpandedReference{idProperties={key={space_omitted}}, of=some(Space{key='{space_omitted}', name='null'})}, history=EmptyReference{referentClass=class com.atlassian.confluence.api.model.content.History}, version=ExpandedReference{idProperties={number=3}, of=some(Version{by=null, when=null, message='null', number=3, syncRev='null', syncRevSource='null', ncsStepVersion='null', ncsStepVersionSource='null', confRev='null', content=EmptyReference{referentClass=class com.atlassian.confluence.api.model.content.Content}})}, ancestors=[Content{id='ContentId{id={id_omitted}}', type=null, title='null', status=current, space=EmptyReference{referentClass=class com.atlassian.confluence.api.model.content.Space}, history=EmptyReference{referentClass=class com.atlassian.confluence.api.model.content.History}, version=EmptyReference{referentClass=class com.atlassian.confluence.api.model.content.Version}, ancestors=null (CollapsedList), container=EmptyReference{referentClass=interface com.atlassian.confluence.api.model.content.Container}, childTypes={}}], container=ExpandedReference{idProperties={}, of=some({id={id_omitted}, type=page})}, childTypes={}})}, version=null} , isSuccessful: false, isAuthorized: true, isValid: false, hasErrors: true, Errors: \"jsonproperty.version.required\""}

 

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian community, loom ai, atlassian loom ai, loom, atlassian ai, record recaps of meetings, meeting recaps, loom recaps, share meeting recaps,

Loom’s guide to great meetings 📹

Join us to learn how your team can stay fully engaged in meetings without worrying about writing everything down. Dive into Loom's newest feature, Loom AI for meetings, which automatically takes notes and tracks action items.

Register today!
AUG Leaders

Atlassian Community Events