Forums

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

Not able to create table of contents programmatically in Confluence via REST API

Jonah Umbro
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 12, 2018

I am trying to create a new Confluence page programmatically using the REST API. Here is the web trace of my JSON request (captured using Fiddler):

POST http://dwvrfpmorin001:8090/rest/api/content HTTP/1.1
Authorization: Basic anVtYnJvOlBhc3N3b3JkMQ==
X-Atlassian-Token: no-check
Accept: application/json
Content-Type: application/json
Host: dwvrfpmorin001:8090
Content-Length: 521
Expect: 100-continue
Connection: Keep-Alive

{
"type":"page",
"title":"My Page",
"space":{"key":"TEAM"},
"body":{
"storage":{
"value":"<p><ac:structured-macro ac:name="toc"/></p><h2>This is a new section</h2><p>here's some regular text</p>",
"representation":"storage"
}
}
}

I get the below following error response:

113
{"statusCode":500,"message":"org.codehaus.jackson.JsonParseException: Unexpected character ('t' (code 116)): was expecting comma to separate OBJECT entries\n at [Source: com.atlassian.confluence.plugins.restapi.filters.LimitingRequestFilter$1@7731274b; line: 8, column: 70]"}
0

 

I know that "<p><ac:structured-macro ac:name="toc"/></p>" is the part of the request that's failing. If I remove that fragment then the page is created successfully.

I've researched this issue extensively and haven't found the solution. It appears to be a bug. We're on v6.3.3 of Confluence. Please help.

 

1 answer

1 vote
Shawn C
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 17, 2018

Hi Jonah, 

Your code looks sound, however we need to escape those quotes; try running a payload like: 

 -d '{"type":"page",
"title":"TOC",
"space":{"key":"TEAM"},
"body":{
"storage":{
"value":"<p><ac:structured-macro ac:name=\"toc\"/></p><h2>This is a New Section</h2><p>here'\''s some regular text</p>",
"representation":"storage"}
}
}'

 

-Shawn 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events