You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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.
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 :
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
this failed Please let us know:
Cheers,
Dario
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Leonid Sokolovskiy @Bahador.Nosrat ,
I can see that [CONFCLOUD-69720] has been marked as fixed. Can you check if the issue is now solved?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
Cheers,
Dario
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ayush Ujjwal ,
I need & in my url .did you find any workaround for this.
Quick link to my problem : https://community.atlassian.com/t5/Confluence-questions/Content-body-cannot-be-converted-to-new-editor-format-if-my-html/qaq-p/1790375#M216349
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I found a solution if it works for you. Replace & in your link with & and check if it works fine. I was able to push the & after replacing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks so much for sharing this!
I spent so much time debugging this error I'd rather not say. Props to figuring it out!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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> - 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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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> - EPCIS (EPC Information Service)</p>",
"representation": "storage"
}
}
}
Now:
Cheers,
Dario
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
sorry it is 27th of March - I have done it today
I would appreciate if you can look at it today
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Stephen Costa ,
Can you check if this is the same issue discussed in:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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, editor2, view 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.