Unable to display codeblock snippets when posting a page with Confluence API.

Sabrina Reyes
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!
April 5, 2021

This question sums up my problem well:

https://community.atlassian.com/t5/Confluence-questions/How-to-save-a-code-block-to-confluence-through-jsonrpc-api/qaq-p/413254?tempId=eyJvaWRjX2NvbnNlbnRfbGFuZ3VhZ2VfdmVyc2lvbiI6IjIuMCIsIm9pZGNfY29uc2VudF9ncmFudGVkX2F0IjoxNjE3NjYwMzMyNDU5fQ%3D%3D

And here is my code:

def _format_page(issuecomments):
    issue_body = markdown.markdown(_format_issue(issue))
issue_body = utils._replace_code(issue_body)
comment_body = _format_comments(comments)
    print(issue_body)
    json = {"type""page",
"title": issue['key'] + ": " + issue['fields']['summary'],
"space": {"key": creds.confl_space},
"body": { "storage": {
"value": issue_body + comment_body,
"representation""storage",
}
}
}
    return json

Above is the code I'm using. Everything works and posts a page on Confluence, except the {code} ... {code} blocks appear in plain text. My goal was to convert a Markdown file to HTML and then post the snippet onto the page. The format is in storage, like the answerer said to do, so what am I doing wrong? Thank you.

Edit: Just to be clear, I am transferring Jira Issues to Confluence pages. This just formats the JSON file - it does not perform any CRUD requests.

1 answer

1 accepted

0 votes
Answer accepted
Thomas Deiler
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 10, 2021

Dear @Sabrina Reyes ,

I recommend to create a sample page with a code block, read the page with an API call and see how it should look like. Eventually you have to convert the read issue data to fit to the confluence json format.

So long

Thomas

Thomas Deiler
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 5, 2021

Dear @Sabrina Reyes ,

was my answer useful? Then I would be happy when you click on the "green accept answer" button.

So long
Thomas

Sabrina Reyes
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!
May 5, 2021

Dear @Thomas Deiler

I did resolve this issue without viewing this answer, but I did the method without having looked at it, so it did help!

I realized my answer had to do with Confluence accepting pure text HTML over markup text.

Be well,

Sabrina

Like Thomas Deiler likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events