Unable to update confluence, getting 500, Internal server error

I have few data in csv file, so I am trying to create table, put csv file data to table and update confluence page. But I am unable to upload data to confluence page its showing 500 internal server error. Below code I am using. Any suggestions pls bash or python is fine. Thanks in advance

set -x

content=$(awk -F',' 'BEGIN{ print "<table><tr><th>Name</th><th>Bounce</th><th>Department</th></tr>"}
           { print "<tr><td>" $1 "</td><td>" $2 "</td><td>" $3 "</td></tr>" } 
           END{ print "</table>"}' input.csv)
#Confluence Calls
response=$(curl -X GET ${confluenceUrl} \
	  -H 'Content-Type: application/json' -k \
	  -u ${confluence_user}:${confluence_password})

version=$((version+1)) #increment the version

response=$(curl -X PUT ${confluenceUrl} \
	  -H 'Content-Type: application/json' -k \
	  -u ${confluence_user}:${confluence_password} \
	  -d '{
		  "id": 123456789,
		  "type": "page",
		  "title": "csv page",
		  "body": {
			"storage": {
				"value": "${content}",
				"representation": "storage"
		  "version": {
			"number": "'"${version}"'"

Hello @Dastagiri ,

Welcome to the Atlassian Developer Community!

Two items I can see here (I ran some tests as well):

  1. Are you getting the correct value of $content here? Try changing this to "value": "'"${content}"'"

  2. After number 1, you might get an invalid JSON body and this is because the result of your awk have some newline and/or white spaces. You can remove the white spaces by using sed or tr. When I was trying it out, I used tr and this one worked for me

content=$(awk -F',' 'BEGIN{ print "<table><tr><th>Name</th><th>Bounce</th><th>Department</th></tr>"}
           { print "<tr><td>" $1 "</td><td>" $2 "</td><td>" $3 "</td></tr>" } 
           END{ print "</table>"}' input.csv | tr -d "[:space:]")

After this, the JSON body in the request was sent properly.

Do try it out and let us know if that works!


Thank you so much @iragudo for your quick response, you saved my life. I am thinking to add something like

UP ↑



to identify easily. Its showing some error like statusCode":400,“data”:{“authorized”:false,“valid”:true,“allowedInReadOnlyMode”:true,“errors”:[],“successful”:false},“message”:“Error parsing xhtml: Unexpected character ‘’’=’’’ (code 61) excepted space, or ‘’’>’’’ or “/>”\n at [row,col {unknown-source}]: [1,632]”,“reason”:“Bad Request”}
2. If we want to append another table to same page then how can we do?
Many Thanks,