Create confluence Page via API and add label at same call

Ansar Rezaei
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.
January 19, 2020

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
Shannon S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 21, 2020

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
AUG Leaders

Atlassian Community Events