I am trying to update an existing Confluence Page from Jenkins. I am using the below command:
curl -u username:password -X PUT -H 'Content-Type: application/json' -d @update.json https://myapp.net/confluence/rest/api/content/${PAGE_ID} | python -mjson.tool.
The update.json has the below content:
'{"id":"3884567","type":"page","title":"JenkinsBuildStatus","space":{"key":"FDRATES"},"body":{"storage":{"value":"<table><tr><td>Hello</td><td>World</td></tr></table>","representation":"storage"}},"version":{"number":"2"}}'
The update of page using the curl command fails with the below error:
{
"message": "",
"reason": "Internal Server Error",
"statusCode": 500
}
It seems the error is due to the '<' and '>' characters inside the body of update.json.
I put backslash \ in front of '<' and '>' like below and that also failed with the same Internal Server Error 500:
'{"id":"3884567","type":"page","title":"JenkinsBuildStatus","space":{"key":"FDRATES"},"body":{"storage":{"value":"\<table\>\<tr\>\<td\>Hello\</td\>\<td\>World\</td\>\</tr\>\</table\>","representation":"storage"}},"version":{"number":"2"}}'
I changed the '<' and '>' with '<' and '>' respectively:
'{"id":"3884567","type":"page","title":"JenkinsBuildStatus","space":{"key":"FDRATES"},"body":{"storage":{"value":"<table><tr><td>Hello</td><td>World</td></tr></table>","representation":"storage"}},"version":{"number":"2"}}'
With these substitutions the curl command could update the page, but in the page the content is not showing as table, instead the page is showing the HTML as text.
Please suggest how this issue can be resolved.
Couple things that might be it. In your update.json is there a reason all your JSON is inside single quotes? I don't think it should be that way. Also, when I do this I do not make the version number a string. I leave it as a number (unquoted).
Thanks for your suggestions. I reexamined my code. The update.json contents are not inside single quotes and the version number is not a String, it is an Interger.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't think you need to escape out the < and > part of the elements. Things that need to be escaped in JSON are ", \, new line, carriage return, and tab.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your suggestion! The < and > symbols without \ (escape) worked.
Actually the root cause was the <br> tag that I added between tables. The update failed with the below error as Confluence Page expected a closing </br> tag:
"message": "Error parsing xhtml: Unexpected close tag </xml>; expected </br>.\n at [row,col {unknown-source}]: [1,1343]",
"reason": "Bad Request",
"statusCode": 400
So I removed the <br> tag and the update succeeded.
Also I tried after adding a <br> as the opening tag and </br> as the closing tag, and the update succeeded.
I tried with adding a <br> as the opening tag and <br/> as the closing tag, and the update failed with same "statusCode": 400 error.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Tables are block level elements anyway, so you should not need a <br>. It is odd that <br/> didn't work as that is how line breaks are stored in Confluence's storage format. Glad it's working though.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks again. I kept <br/> only between two tables and that worked.
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.