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

Create confluence Page via API and add label at same call Edited

Hi

I need to create a page in confluence with label on it with the same call. Here is my API Call.

curl --location --request POST 'http://ism218:8090/confluence/rest/api/content/' --header 'Content-Type: application/json' --header 'Authorization: Basic YXJlemFlaTpBcjkyNjczMjc5IUA=' --data-raw '{
"type":"page",
"title":"page title123321123",
"space":{
"key":"sadad"
},
"body":{"storage":{"value":"abc","representation":"storage"}},
"metadata":{
"labels":[{"name":"sre"},{"name":"kpt"}]
}
}'

There is a suggestion in StackOverflow that consider this as metadata:

"metadata": {
"labels": [
{
"prefix": "global",
"name": "label1"
},
{
"prefix": "global",
"name": "label2"
}
]
}
}'

 Both of them Create the page, but none of them adds a label to it.

Could you provide some advice for me about this?

Follow-up question:

How I could phrase multiline string data as Body Storage value. For example, I want to create a page via API with this content:

<ac:structured-macro ac:macro-id="5e1cdf32-bcbe-4243-ba55-041d1ed1ee74" ac:name="panel" ac:schema-version="1">
<ac:rich-text-body>
<ac:structured-macro ac:macro-id="8372796a-22ec-4b34-bbfb-d19464e0a12c" ac:name="info" ac:schema-version="1">
<ac:rich-text-body>
<p>
<br/>
</p>
</ac:rich-text-body>
</ac:structured-macro>
<ac:structured-macro ac:macro-id="ed9b94a0-af84-4f26-95b7-b567b1a036a0" ac:name="tip" ac:schema-version="1">
<ac:rich-text-body>
<p>
<br/>
</p>
</ac:rich-text-body>
</ac:structured-macro>
</ac:rich-text-body>
</ac:structured-macro>

and I should provide this at Body Storage Value of my JSON:

"body":{"storage":{"value":"here","representation":"storage"}},

 

1 answer

0 votes

Hello Ansar,

Thank you for your patience earlier with the spam system! I combined your two API questions here so I can answer them directly.

For your first question, a few people from the Community discussed the same thing in the following thread:

You can use the example at Confluence REST API examples under Read content, and expand the body if you want to see how the body is supposed to look and use that as an example for creating your page.

I hope that helps but let me know if you have any trouble.

Regards,

Shannon

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Confluence

Lessons and Learnings: Six Months of Working Remote [Discussion]

Hey there, folks! For most of us, the past six months- yes, you read that right- have been a journey. More people than ever before have pivoted to working remotely, and navigating being on-scre...

8,411 views 6 6
Join discussion

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