Creating Page via API - page tree macro

Zain Ali August 5, 2022

Hi,

I am creating confluence pages via API.

I want the page to have page tree with @self as root.

I can do this in confluence but not sure how to do it via API.

Any help is appreciated!

2 answers

0 votes
Levin Oertle December 22, 2022

In the API doku I found this part and like this it works:

 

The updated body of the content. Does not apply to attachments. If you are not sure how to generate these formats, you can create a page in the Confluence application, retrieve the content using Get content, and expand the desired content format, e.g. expand=body.storage.

You will get something like this:

<p><ac:structured-macro ac:name="pagetree" ac:schema-version="1" ac:local-id="LOCAL_ID" ac:macro-id="MACRO_ID"><ac:parameter ac:name="root"><ac:link><ri:page ri:content-title="@self" /></ac:link></ac:parameter><ac:parameter ac:name="expandCollapseAll">true</ac:parameter><ac:parameter ac:name="startDepth">1</ac:parameter></ac:structured-macro></p>

If you now create a page over api you can just pass this code block with the item.

Should look something like this:

{
"title": "YOUR_TITLE",
"type": "page",
"space": {
"key": "YOUR_SPACE_KEY"
},
"status": "current",
"ancestors": [
{
"id": "SOME_PAGE_ID"
}
],

"body": {
"storage": {
"value": "<p><ac:structured-macro ac:name='pagetree' ac:schema-version='1' ac:local-id='LOCAL_ID' ac:macro-id='MACRO_ID'><ac:parameter ac:name='root'><ac:link><ri:page ri:content-title='@self' /></ac:link></ac:parameter><ac:parameter ac:name='expandCollapseAll'>true</ac:parameter><ac:parameter ac:name='startDepth'>100</ac:parameter></ac:structured-macro></p>",
"representation": "storage"
}
}
}
0 votes
Neil
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 8, 2022

Hi @Zain Ali. Check out the Copy page hierarchy API method.

https://developer.atlassian.com/cloud/confluence/rest/api-group-content---children-and-descendants/#api-wiki-rest-api-content-id-pagehierarchy-copy-post

From the docs: Copy page hierarchy allows the copying of an entire hierarchy of pages and their associated properties, permissions and attachments. The id path parameter refers to the content id of the page to copy, and the new parent of this copied page is defined using the destinationPageId in the request body. 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events