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

"Content body cannot be converted to new editor format" error when updating page content

Leonid Sokolovskiy March 25, 2020

API call work when I send a request from Postman but not from c# code.

 

As an experiment I have just get content from a page, and then update page.

If I send request from Postman it works but not from code.

I checked requests in Fiddler and they are almost indentical.  There are some Postman specific items in the header.

Any ideas how can I troubleshoot it?

 

Some addition - actually pages with simple content updated ok.

I would appreciate if somebody provide some hints.

 

8 answers

1 accepted

2 votes
Answer accepted
Leonid Sokolovskiy March 31, 2020

Ok, I found the problem. Probably I could have found it easier if your error message was actually correct.

The reason that some pages cannot be updated with the error :

Content body cannot be converted to new editor format

 

there is no User-Agent header!!!!

User-Agent should be set to something - otherwise looks like you have null reference exception during the conversion procedure. This looks like a bug to me.

Bahador.Nosrat March 31, 2020

i've been watching this as i'm experiencing the same problem. i'm going to try the user agent.

 

tangential: i've heard that chrome is going to phase out the use of user agent

Bahador.Nosrat March 31, 2020

adding the user agent worked for us as well. thank you @Leonid Sokolovskiy

Like Dario B likes this
Leonid Sokolovskiy March 31, 2020

@Bahador.Nosrat  you are welcome :)

Like # people like this
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 1, 2020

Nice catch @Leonid Sokolovskiy ! :) 

I noticed there was not user-agent in the logs but I did not think it could have been causing the issue.

 

At this point, since per RFC 7231 the user agent is not mandatory:

A user agent SHOULD send a User-Agent field in each request unless specifically configured not to do so.

And since the error message is indeed misleading:

Error rendering content for view: RuntimeException occurred while performing an XHTML storage transformation (null)

 

I have proceeded opening a bug ticket for this issue:

Please vote for the above bug ticket and set yourself as a watcher so that you will be notified in case of any update/progress. The bug will be addressed according to the Atlassian Cloud bug fixing policy.

 

 

Cheers,
Dario

Atharva_Pendse April 15, 2020

I am experiencing this issue as well (using the requests library in python), even after providing a User-Agent header. For context, I am trying to update a table in a confluence page. My headers are 

write_headers = { "Accept": "application/json", 
"Content-Type": "application/json",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36"
}

 I can verify that my authentication credentials are correct, since a read request works as expected.

 

Any help will be appreciated. Thanks.

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 16, 2020

@Atharva_Pendse ,

this failed Please let us know:

  1. Confluence URL
  2. The status code and eventual error message returned
  3. Time date and timezone of the last time you tested this
  4. If the sending exactly the same request with Curl or Postman works as expected

 

Cheers,
Dario

Atharva_Pendse April 16, 2020

@Dario B ,

1. The api url is https://confluentinc.atlassian.net/wiki/rest/api/content/1193612051

2. Here is the request response:

{
19:20:47      "data": {
19:20:47          "authorized": false,
19:20:47          "errors": [],
19:20:47          "successful": false,
19:20:47          "valid": true
19:20:47      },
19:20:47      "message":  "com.atlassian.confluence.api.service.exceptions.BadRequestException: Content body cannot be converted to new editor format",
19:20:47      "statusCode": 400
19:20:47  }

3. This was tested April 15th Pacific time in the evening.

4. I have not had a chance to test this due to our current infrastructure, but note that sending the same request with a simpler content works with python, just like the original post described.

 

Thank you.

Leonid Sokolovskiy April 16, 2020

But what is the request?

Could you provide json.

 

Make an experiment - read page content and the update it, without any modifictation - does this work (you need to ncrease version number otherwise you will get 409)?

Are you sure you correctly send body content?

Like Dario B likes this
Atharva_Pendse April 16, 2020

I can confirm that the request is correct, because weirdly, I realized that it actually works sometimes (with the exact same request body). Around 50% of the time, it fails with the response above.

I can't provide the json unfortunately since it has confidential info. And yes, I do increment the version number (the status code in the response is 400 not 409)

Leonid Sokolovskiy April 16, 2020

 

Try to run it with Fiddler and try to get both successful and not successful requests - for the same page and see whether there are any differences (headers and body).

If Atlassisan provides more information about an error it will possibly help.

I am a bit suspicious that exactly the same request succeeds 50% of times

Like Dario B likes this
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 17, 2020

@Leonid Sokolovskiy  @Bahador.Nosrat ,

I can see that [CONFCLOUD-69720]  has been marked as fixed. Can you check if the issue is now solved?

 

@Atharva_Pendse 

As already suggested, if 50% of the requests fails there can be something different and it would be best if you can  inspect them as already suggested.

Otherwise, searching the logs for your instance for requests against that endpoint that returned 400 I can see below results, can you confirm I should check the ones having 'python' as the user-agent?

Time| Method | Status Code| Duration | Request ID | Request URL | User Agent

2020-04-15 00:57:42.034 PUT 400 0.081334 e9349299be273066 /wiki/rest/api/content/1193612051 python-requests/2.23.0

2020-04-16 00:12:26.052 PUT 400 0.100290 784958efda94712b /wiki/rest/api/content/1193612051 python-requests/2.23.0

2020-04-16 01:05:15.950 PUT 400 0.177457 4c88b2d6e4a25e28 /wiki/rest/api/content/1193612051 placeholder

2020-04-16 04:06:25.594 PUT 400 0.126249 94e4c79736153677 /wiki/rest/api/content/1193612051 Chrome/77.0.3865.90

2020-04-16 04:20:47.524 PUT 400 0.118750 7f97ec9288d9d726 /wiki/rest/api/content/1193612051 Mozilla/5.0%20(Macintosh;%20Intel%20Mac%20OS%20X%2010_15_3)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/81.0.4044.92%20Safari/537.36

2020-04-16 19:31:47.889 PUT 400 0.158130 7cb91228a3988f21 /wiki/rest/api/content/1193612051 Mozilla/5.0%20(Macintosh;%20Intel%20Mac%20OS%20X%2010_15_3)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/81.0.4044.92%20Safari/537.36

2020-04-16 19:47:51.655 PUT 400 0.082288 64ea9b11c002e6a9 /wiki/rest/api/content/1193612051 PostmanRuntime/7.24.1

2020-04-16 21:44:45.986 PUT 400 0.152681 1a7ad8d4a7ca9da5 /wiki/rest/api/content/1193612051 Mozilla/5.0%20(Macintosh;%20Intel%20Mac%20OS%20X%2010_15_3)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/81.0.4044.92%20Safari/537.36

 

Have a nice weekend,

Dario

Jan Frei April 23, 2020

@Dario B 

The issue still persists on our instances. Maybe it's not connected to this one, but the error message is the same:

"com.atlassian.confluence.api.service.exceptions.BadRequestException: Content body cannot be converted to new editor format" (StatusCode: 400)

What I've figured out is that page links do cause issues (and it doesn't matter whether we set a User-Agent or not). Here is a PUT call with a page link which throws this error mentioned above:

{
type: 'page',
body: {
storage: {
representation: 'storage',
value: '<p><ac:link ac:card-appearance="inline"><ri:page ri:content-title="TestPage" ri:version-at-save="1" /><ac:link-body>TestPage</ac:link-body></ac:link> </p>',
},
},
version: {
number: oldVersion + 1,
},
title: pageTitle,
}

Btw I just copy-pasted the storage format from a page with a page link and didn't change anything.

 

Does anyone experience the same issue ?

 

Cheers,

Jan

Like # people like this
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 29, 2020

@Jan Frei ,

The issue you are facing is the same being discussed in the below thread on the Developers Community:

 

By reading there, it looks like the issue is that the space key is not returned when getting the storage format of the page and therefore not added to the PUT request:

ri:space-key="xxx"    

 

As documented in the documentation page Confluence Storage Format - Links (for Server but still applicable):

AN EXAMPLE OF DIFFERENT LINK BODIES
<ac:link>
  <!-- Any resource identifier --> 
  <ri:page ri:content-title="Home" ri:space-key="SANDBOX" /> 
  <ac:link-body>Some <strong>Rich</strong> Text</ac:link-body>
</ac:link>
...

 

Can you try adding the missing ri:space-key and let me know if this solves the issue?

Also:

  1. I have created a bug ticket for this issue that you can vote and follow for updates: https://jira.atlassian.com/browse/CONFCLOUD-69902
  2. In case of further questions, you may want to continue in the other thread since this one is related to a different issue that has already been addressed.

 

Cheers,
Dario

Like # people like this
Jan Frei April 29, 2020

Hi @Dario B

Thank you very much for your response.

Yes, it worked when I added the "ri:space-key" attribute.

However, I think that a "ri:space-key" attribute shouldn't be mandatory here since the link's target is in the same space.

I'm following the ticket on your JIRA and I'm looking forward to a fix.

 

Cheers,

Jan

Like # people like this
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 29, 2020

Thanks for quick reply @Jan Frei ,

You are right, if not returned it should not be needed too, and actually it should not be needed at all if the linked page is on the same space. 

Please follow the bug ticket and the developer's thread to get updates on this. 

 

Cheers,
Dario

Like Jan Frei likes this
John Wheeler May 26, 2020

Adding the space key fixed it for me.

Like # people like this
3 votes
Ayush Ujjwal August 27, 2021

I was facing the same issue. I was using python for the requests and was unable to find why it was happening and finally after a lot of debugging and coffee I found the issue might also occur if you have a & in your body.storage.value. Do check it and replace the & with something else.

Kommaraju Ajay Kumar August 30, 2021
Ayush Ujjwal August 30, 2021

I haven't found any workaround yet on the problem you are facing. Since & is mandatory in your case there will need some modifications to send the params without the error causing trouble. Will let you know in case I find something. If you get any solution do post here as well. Cheers.

Like Kommaraju Ajay Kumar likes this
Ayush Ujjwal August 30, 2021

I found a solution if it works for you. Replace & in your link with &amp; and check if it works fine. I was able to push the & after replacing.

Like # people like this
Kommaraju Ajay Kumar August 30, 2021

Hi Ayush,
you are a saviour , I can't thank enough for this workaround. 
Really appreciate it.I am able to push the link to confluence.
Regards,
Ajay

Ayush Ujjwal August 30, 2021

That's great to hear Ajay : ) . Cheers.

Like Kommaraju Ajay Kumar likes this
Andraž Zvonar November 24, 2022

Thanks so much for sharing this!

I spent so much time debugging this error I'd rather not say. Props to figuring it out!

2 votes
Yurii Petrovskyi November 10, 2020

In my case I changed <br> tag to <br/> in "value".

Wouter Jonker December 27, 2020

This worked for me!

Like # people like this
1 vote
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 26, 2020

Hello @Leonid Sokolovskiy ,

If the same exact request works with Postman but it does not work from your code, the problem must be somewhere in your code.

One thing you can do is to modify your code so that it will print to the logs (or to the console) the full request body, the endpoint and method and headers before sending the request.

This way you can compare what is generated by your code with the working request in Postman.

However, since the error in the summary refers to converting the content body in your request to the new format, and since you  say everything works fine when updating a simple page, there are chances the issue is related to the representation used in your request or with the body.value or similar (see the workaround of CONFCLOUD-68057  for details).

Now, in case nothing works, can you kindly provide:

  • The exact steps you follow when testing this with Postman
  • Endpoint called and method used (I believe it is PUT /wiki/rest/api/content/{id} but please confirm)
  • Complete request body (remove sensitive data, if any)
  • Authentication method

 

Please also confirm you are trying to update a page created with the new editor.

 

Finally, for the future, please notice that this might not the best place to get help on development related questions. You have much higher chances to get help on development related question using the links you can find in https://developer.atlassian.com/resources. Specifically:

 

Cheers,
Dario

Leonid Sokolovskiy March 26, 2020

1. just give you a bit more details of how I did the test 

- it the debugger I have a copy and then pasted json content to Postman

- in the code, only 2 statements left 

var data = new StringContent(json, Encoding.UTF8, "application/json");

response = await _client.PutAsync(url, data);  - client is a standard HttpClient

not that many things could go wrong but I will appreciate your feedback

2. I compared 2 requests in Fiddler and could not find differences 

3. And ... for some pages everything works OK. - the same code

I am new to the Confluence development so I will try the developers community.

 

thank you.

Leonid Sokolovskiy March 26, 2020

Here is the final json sent both in Postman and in the code (this is the most simple one which does not work)

 

{"version":{"number":21},"type":"page","title":"page13","status":null,"body":{"storage":{"value":"<table data-layout=\"default\"><tbody><tr><th><p>XXX</p></th><th><p>Location</p></th><th><p>Operated By</p></th><th><p>Handles Products</p></th><th><p>Outbound</p></th><th><p>Inbound</p></th></tr><tr><td><p>DC 1</p></td><td><p>XXX</p></td><td><p>XXX</p></td><td><p>APP</p></td><td><p>x</p></td><td><p>Q1 2020</p></td></tr><tr><td><p>DC 2</p></td><td><p>XXX</p></td><td><p>XXX</p></td><td><p>FTW</p></td><td><p>x</p></td><td><p>Q1 2020</p></td></tr><tr><td><p>DTC</p></td><td><p>XXX</p></td><td><p>XXX</p></td><td><p>APP, FTW, OMNI</p></td><td><p>x</p></td><td><p>x</p></td></tr><tr><td><p>XXX</p></td><td><p>XXX</p></td><td><p>XXX</p></td><td><p>APP, FTW, OMNI</p></td><td><p>x</p></td><td><p>Q3 2020</p></td></tr></tbody></table><p><strong>Global</strong>&nbsp;- EPCIS (EPC Information Service)</p>","representation":"storage"}}}

 

also tried it with "status" : "current" - result is the same.

Endpoint -  PUT https://detego.atlassian.net/wiki/rest/api/content/144606710 

I am using Basic authentication.

 

Do you need more details?

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 27, 2020

Hi @Leonid Sokolovskiy ,

I can confirm that the provided body works fine against a page created with both, new and old editor.

I had to modify it to apply to my instance like below but everything worked fine:

{
"version": {
"number": 2
},
"type": "page",
"status": "current",
"title": "New Editor",
"body": {
"storage": {
"value": "<table data-layout=\"default\"><tbody><tr><th><p>XXX</p></th><th><p>Location</p></th><th><p>Operated By</p></th><th><p>Handles Products</p></th><th><p>Outbound</p></th><th><p>Inbound</p></th></tr><tr><td><p>DC 1</p></td><td><p>XXX</p></td><td><p>XXX</p></td><td><p>APP</p></td><td><p>x</p></td><td><p>Q1 2020</p></td></tr><tr><td><p>DC 2</p></td><td><p>XXX</p></td><td><p>XXX</p></td><td><p>FTW</p></td><td><p>x</p></td><td><p>Q1 2020</p></td></tr><tr><td><p>DTC</p></td><td><p>XXX</p></td><td><p>XXX</p></td><td><p>APP, FTW, OMNI</p></td><td><p>x</p></td><td><p>x</p></td></tr><tr><td><p>XXX</p></td><td><p>XXX</p></td><td><p>XXX</p></td><td><p>APP, FTW, OMNI</p></td><td><p>x</p></td><td><p>Q3 2020</p></td></tr></tbody></table><p><strong>Global</strong>&nbsp;- EPCIS (EPC Information Service)</p>",
"representation": "storage"
}
}
}

 

Now:

  1. Can you confirm you use basic authentication with email address and API Token and not username and password?
  2. Can you confirm that the REST request always work in Postman, also for those pages that fail from your code? 
  3. Also, I can see you have access to 3 instances, d*.atlassian.net, h*.atlassian.net and l*.atlassian.net. Can you let me know against which instance are you sending the request together with date, time and timezone of the last time you get the error so that I can see if I find anything in the logs (please also confirm the error message returned).

 

Cheers,
Dario

Leonid Sokolovskiy March 27, 2020

1. I use API token

2. In cases I have tried - in Postman it works, in Code - some pages works, some not

3. d*.atlassian.net

did run it twice (both failed) at 12:37 27th Feb UK time

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 27, 2020

Hi @Leonid Sokolovskiy ,

Unluckily we don't have the logs anymore from the 27th of February. 

Would it be possible for you to repeat the test and provide new date/time?

 

Have a nice weekend.

 

Cheers,
Dario

Leonid Sokolovskiy March 27, 2020

sorry it is 27th of March - I have done it today

I would appreciate if you can look at it today 

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 31, 2020

Hello @Leonid Sokolovskiy ,

I have checked the logs and I can confirm that the problem is somewhere in your code:

_time Source IP Method Code Duration Request ID Request URL Query Refers To User Agent

2020-03-27 13:37:06.624 81.106.202.209 PUT 400 0.406615 d50f15d45b0650bb /wiki/rest/api/content/144606710 - - -


2020-03-27 13:37:19.255 62.46.169.65 PUT 200 0.215263 6ff1540aee9379cf /wiki/rest/api/content/174227670/ status=draft&action=sync https://<NAME>.atlassian.net/ Mozilla/5.0%20(Windows%20NT%2010.0;%20Win64;%20x64;%20rv:74.0)%20Gecko/20100101%20Firefox/74.0
 

2020-03-27 13:37:23.029 62.46.169.65 PUT 200 0.741400 6b43ee5ad98b0123 /wiki/rest/api/content/174227670/ status=draft&action=publish https://<NAME>.atlassian.net/ Mozilla/5.0%20(Windows%20NT%2010.0;%20Win64;%20x64;%20rv:74.0)%20Gecko/20100101%20Firefox/74.0
 

2020-03-27 13:37:23.799 81.106.202.209 PUT 400 0.318233 3475e1ebb82d751c /wiki/rest/api/content/144606710 - - -

 

Indeed, looking at above logs (times are GMT+1, so the failed requests are at 13:37) I can see that the status code returned for the failed requests is "400: BAD REQUEST". 

 

Therefore: if everything works fine when sending the request using Postman or Curl, but the request fails when sent from your C# code (returning status 400), most likely your code is creating an invalid request body by maybe adding some extra quotes or spaces or anything similar. 

I will now dig a bit more but, as I already said, it would be best if you could print to the logs the full request body created by your code and compare it to the working from Postman using diff or similar tools. 

 

Cheers,
Dario

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 31, 2020

To provide more context, the logs in Confluence are showing:

2020-03-27 13:37:06.521 ERROR com.atlassian.confluence.content.render.xhtml.DefaultRenderer Error rendering content for view: RuntimeException occurred while performing an XHTML storage transformation (null)   

com.atlassian.confluence.content.render.xhtml.XhtmlException: RuntimeException occurred while performing an XHTML storage transformation (null)


com.atlassian.confluence.content.render.xhtml.atlassiandocformat.StorageXhtmltoADFTransformer.transform(StorageXhtmltoADFTransformer.java:115)

com.atlassian.confluence.content.render.xhtml.DefaultRenderer.renderWithoutMetrics(DefaultRenderer.java:188)

com.atlassian.confluence.content.render.xhtml.DefaultRenderer.renderWithResult(DefaultRenderer.java:145)

com.atlassian.confluence.content.render.xhtml.DefaultFormatConverter.convertToAtlasDocFormatWithResult(DefaultFormatConverter.java:174)

com.atlassian.confluence.api.impl.service.content.ContentBodyConversionManagerImpl.computeConvertedValue(ContentBodyConversionManagerImpl.java:400)

[.....]
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:748)

 

Caused by: java.lang.NullPointerException: 

java.util.regex.Matcher.getTextLength(Matcher.java:1283)
java.util.regex.Matcher.reset(Matcher.java:309)
java.util.regex.Matcher.<init>(Matcher.java:229)
java.util.regex.Pattern.matcher(Pattern.java:1093)
com.atlassian.confluence.mobile.MobileUtils.getIosAppVersion(MobileUtils.java:33)
[...]
... 367 more

 

2020-03-27 13:37:06.521 WARN com.atlassian.confluence.api.impl.service.content.ContentBodyConversionManagerImpl Could not convert storage format to atlas_doc_format  format using ceo with id : -1  

 
0 votes
Vinci Wu August 31, 2022

@Leonid Sokolovskiy 

I've only recently stumbled across this error.  I updated a table records to wiki page. When I limitd table records to 100, it can work. But I select all records(1000 row), it failed.

update wiki {"statusCode":400,"data":{"authorized":true,"valid":true,"errors":[],"successful":true},"message":"com.atlassian.confluence.api.service.exceptions.BadRequestException: Content body cannot be converted to new editor format"}

 

payload = {
"type":"page",
"title": f'{wiki_title_name}',
"space":{
"key":"DataScience"
},
"body":
{
"storage":{
"value":html,
"representation":"storage"
}
}
}

"html" is strings include table records with html code.

I don't know if there is  long limit in "value" string.

Vinci Wu August 31, 2022

It is python code.

0 votes
Stephen Costa October 29, 2021

I've only recently stumbled across this error. We have an automation that uses the confluence API to update a page. This process was working correctly until Oct 5 when we started getting the `Content body cannot be converted to new editor format` error.

  • Same issue in Postman and in our original python code
  • The user-agent header is supplied
  • There aren't any `ri:` elements so I don't think there's anywhere to add the `ri:space` key. Maybe I'm wrong?
  • I don't see anywhere to select Editor v1 when creating/editing a page so I can't try sending the same page content there as suggested.

None of these solutions seem to work for me. Is there any other suggestion? This feels like either a bug on Confluence side or a bad error message I can't get around.

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 2, 2021
0 votes
Philip Colmer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 5, 2021

In case someone finds this question, as I did, while trying to troubleshoot this problem, I have found another reason why you might get this error back.

If you are creating or updating a page that is set to use the v2 editor and your content is syntactically incorrect in some way, you don't get the syntax error message back, you get the "Content body cannot be converted..." error.

So, if you find yourself getting this error message, try creating a v1-editor page and send the content there and you might get the correct syntax error message back, thus helping to diagnose the problem.

0 votes
Leonid Sokolovskiy March 31, 2020

Honestly, I am not convinced. 

You are getting null reference exception and I am just passing all required filed in PUT request.

I have made tests for different formats : editor, editor2view and everything works - and the code is exactly the same except in body (json)  formation representations are different.

 

"representation": "storage"

used different formats here.  If we asume that the problem if the body value that we should expect it should not work with other formats.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events