Forums

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

Code Macro via Confluence REST API

Zu Jiry August 3, 2022 edited
Hello, I want to send a codeblock macro via REST API. I am using Pythons Confluence library and this code snippet: 
<ac:structured-macro ac:name="code">
    <ac:parameter ac:name="title">test.py</ac:parameter>
    <ac:plain-text-body>
    def authenticate():
      confluence = Confluence(
          url='https://confluence.custom.de',
          username=os.environ['CONFLUENCE_USER'],
          password=os.environ['CONFLUENCE_API_TOKEN'],
          cloud=False
      )
      return confluence
    </ac:plain-text-body>
</ac:structured-macro> 
Neither plain-text-body nor rich-text-body are recognized by Confluence. The result is an empty codeblock.
My question therefore: How can I add text to the codeblock in this structure?

1 answer

1 accepted

0 votes
Answer accepted
Dominic Lagger
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 3, 2022

Hi @Zu Jiry 

Can you try with: 

<ac:structured-macro ac:name="code">
<ac:plain-text-body>
<![CDATA[def authenticate(): confluence = Confluence( url='https://confluence.custom.de', username=os.environ['CONFLUENCE_USER'], password=os.environ['CONFLUENCE_API_TOKEN'], cloud=False ) return confluence
]]>
</ac:plain-text-body>
</ac:structured-macro>

Let me know if this worked.

Regards, Dominic 

Zu Jiry August 3, 2022

Thank you! Works like a charm

3rdjkadjk
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 1, 2023 edited

@Zu Jiry @Dominic Lagger  How does one know a specific "code" of ac:macro/macro ID ?

Or where should i get them in confluence ?

Zu Jiry July 4, 2023

@3rdjkadjk Hi.

So, the workaround I used is to use the macro in confluence where you can just implement it normally. Then look at the page source code (HTML) of it.

Be mindful, that you might not need to implement every parameter yourself found in the HTML code. There are some, that confluence automatically adds, but you will have to figure out which ones...

Like • Clayton Stovall likes this

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, knowledge sharing, intentional knowledge sharing playbook, loom, confluence, team collaboration, knowledge management, workplace productivity, information silos, documentation best practices, internal communication, knowledge sharing strategies

Conquer collaboration chaos with Loom + Confluence

You don't need more tools. You need tools that actually work together – the way humans do. See how Loom + Confluence help teams collaborate with more context, more connection, and fewer calendar invites. 💪

See inside
AUG Leaders

Atlassian Community Events