Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

Edited

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 Apr 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 May 05, 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

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
Community showcase
Published in Confluence Cloud

🎨 Add some visual life to your templates

Hi Atlassian Community, My name is Avni Barman, and I am a Product Manager on the Confluence Cloud team. Based on feedback from you, we are giving admins more power to create templates that a...

164 views 1 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you