How do I display checkboxes correctly in the API?

Naruse Murai April 7, 2024

I made a request like this based on the here answer, but the checkbox is not displayed correctly in Confluence.

curl --request PUT \
--url "https://$domain/wiki/api/v2/pages/$pageid" \
--user "$user:$token" \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"id": "<page id>",
"status": "current",
"title": "Create Page from Confluence API",
"body": {
"representation": "storage",
"value": "[] check1"
},
"version": {
"number": 2,
"message": "v2.0"
}
}'

 

In confluence it looks like this.


スクリーンショット 2024-04-08 11.29.12.png


Is there a way to display it correctly?

1 answer

1 accepted

0 votes
Answer accepted
Kyle Long
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 8, 2024

Hi,

- Confluence cloud has moved away from wiki markup (confluences version of markdown)

- Rest api does not support Markdown (the editor does)

Internal storage of pages is in an xml storage format. Hence If you wish to use check boxes and other formatting use xml


E.g
[ ] checkmark box 1

[ ] checkmark box 2


 would look like In xml:

<ac:task-list>
  <ac:task>
    <ac:task-status>incomplete</ac:task-status>
    <ac:task-body>checkmark box 1</ac:task-body>
  </ac:task>
  <ac:task>
    <ac:task-status>incomplete</ac:task-status>
    <ac:task-body>checkmark box 2</ac:task-body>
  </ac:task>
</ac:task-list>

 

API request:

curl --request PUT \
 --url "https://$domain/wiki/api/v2/pages/$pageid" \
 --user "$user:$token" \
 --header 'Accept: application/json' \
 --header 'Content-Type: application/json' \
 --data '{
   "id": "<page ID>",
   "status": "current",
   "title": "Create Page from Confluence API",
   "body": {
     "representation": "storage",
     "value": "<ac:task-list><ac:task><ac:task-status>incomplete</ac:task-status><ac:task-body>checkmark box 1</ac:task-body></ac:task><ac:task><ac:task-status>incomplete</ac:task-status><ac:task-body>checkmark box 2</ac:task-body></ac:task></ac:task-list>"
   },
   "version": {
     "number": 10,
     "message": "v4.0"
   }
}'

Screenshot 2024-04-09 at 8.53.51 AM.png 

Naruse Murai April 9, 2024

@Kyle Long 

We confirmed that it works as expected with xml storage format. thank you :) 


By the way, are there any tools available to convert GitHub Markdown to xml storage format?

Kyle Long
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 11, 2024

There doesn’t seem to be a good way to convert markdown -> XML(compatible with confluence).
Points of note:
- Confluence Rest api does not support markdown (you can input to the editor)

- Confluence stores data in and xml/xhtml like form

- Github markdown is an extension of pure markdown and can include some HTML

For context, I attempted the vite README.md

Approaches I tried:

  1. Converting the file to html and manually editing
    1. Convert .md file to HTML with pandoc:
      $>pandoc -s -o output.html vite_markdown.md
    2. Trimmed all the /n and escaped all the quotes “
      $>tr -d '\n' < output.htm | sed 's/\"/\\"/g' > output_formatted.html
    3. Manually removed incompatible HTML tags like:
      <br> <img> <code>
    4. This kinda worked but it was a massive pain and if your markdown is complicated or you have many files this wouldn’t work
  2. Asking ChatGPT
    1. This works on simple markdown but anything complex like the above with included HTML it struggles to produce anything of value.
  3. Mark tool — a tool for syncing your markdown documentation with Atlassian Confluence pages.
    1. Note this is not an atlassian tool however it’s the only tool that I could find that is recently updated that works.
    2. The tool can be used like this:
      $>mark -b $base_url -u $myemail -p $token -l $space -f vite_markdown.md
      1. Where:
            base_url=https://<your_site>.atlassian.net/wiki
            myemail=<your atlassian account email>
            token=<your_apitoken>
            space=<your space name>
        In the top of your markdown file also include the metadata headings:
            <!-- Space: <your test space name> -->
            <!-- Title: <title of the page you are updating>-->
    3. Use the –debug flag to help debug issuesThis should result in the tool converting the markdown and posting it to the specified confluence page
      2024-04-11_16-34-26.png
    4. Caveats:
      1. If your .md uses a combination of html as well you may still need to trim the tags that will cause it to fail or use pandoc to only convert the HTML parts
        1. Cut the html parts and convert with pandoc
          $>pandoc html_part.html -f html -t markdown -s -o html_converted.md
        2. Recombine to the original file
        3. Add the metadata headers
        4. Run mark tool

Final thoughts if you only have a few simple files, try a combination of converting the file formats chatgpt and manually editing to get the job done. If you are dealing with many files and want to do it programmatically Mark tool could be a good option (I got the best results, with no manual editing). Note the image below is the process of cutting html converting and recombining with MD. It’s not a perfect result and some image sizes are off but I’d say its about 92% accurate without any manual edits and if you edit the doc in confluence later you can fix some of the sizing and spacing.

Screenshot 2024-04-11 at 5.05.08 PM.png

Like Naruse Murai likes this
Naruse Murai April 11, 2024

Thank you for answering.
I was trying to convert it programmatically, but Mark tool doesn't seem to support `<ac:task*>`, so I'll try to implement it myself.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events