How do you insert a confluence macro into a page created by the Confluence Rest Api?

六眼飞鱼酱① 提交于 2019-12-09 14:31:12

问题


I've successfully used the Confluence Rest API to create a page and attach it to a Space. MY json looks much like that from the example:

{
"type":"page","title":"My Example Page 1", "space": {"key":"DAT"},
"body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}
}

If I create a page interactively in Confluence, I'm given a list of canned macros when I click the 'Edit' button like 'Attachments' or 'Activity Stream'.

What is the right json value to create a page with the Attachments Macro as the body instead of 'This is a new page'?

Something like below (which is totally made up):

{
"type":"page","title":"My Example Page 1", "space": {"key":"DAT"},
"body":{"storage":{"value":"**Attachments_Macro_Block**","representation":"storage"}}
}

What would I substitute for 'Attachments_Macro_Block' in the json to get the resultant page to display the macro block?


回答1:


As luck would have it, after I posted this question I stumbled on the answer. So for the benefit of others, here is what I found.

This page provided the missing pieces: Confluence Attachment Macro Help

My JSON looked like this:

{
"type":"page",
"ancestors":
    [
        {
            "type":"page",
            "id":12355342
        }
    ],
"title":"Page Title 1",
"space":
    {
        "key":"DAT"
    },
"body":
    {
        "storage":
            {
                "value":"<ac:structured-macro ac:name=\"attachments\">
                <ac:parameter ac:name=\"old\">false<\/ac:parameter> <ac:parameter ac:name=\"patterns\">*<\/ac:parameter> 
                <ac:parameter ac:name=\"sortBy\">name<\/ac:parameter> <ac:parameter ac:name=\"sortOrder\">ascending<\/ac:parameter> 
                <ac:parameter ac:name=\"labels\"><\/ac:parameter> <ac:parameter ac:name=\"upload\">false<\/ac:parameter> <\/ac:structured-macro>",
                "representation":"storage"
            }
    }
}


来源:https://stackoverflow.com/questions/30194918/how-do-you-insert-a-confluence-macro-into-a-page-created-by-the-confluence-rest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!