首页 > 解决方案 > 使用 Confluence API 使用 IFrame 宏创建页面

问题描述

我正在使用以下简单的 curl 调用来创建一个新的 Confluence 页面,其中包含一个引用外部站点的嵌入式 IFrame 宏:

curl -u <username>:<password> -X POST -H 'Content-Type: application/json' -d '{"type":"page","title":"A Test Page", "space":{"key":"SPACE"}, "ancestors" : [ { "id": "115328548" } ],"body":{"storage":{"value":"<h1>IFrame Macro Test</h1><p>Foo Bar Blah</p><p><ac:structured-macro ac:schema-version=\"1\" ac:name=\"iframe\"><ac:parameter ac:name=\"URL\">https://www.example.com</ac:parameter><ac:parameter ac:name=\"Width\">100%</ac:parameter><ac:default-parameter>https://www.example.com</ac:default-parameter></ac:structured-macro></p>","representation":"storage"}}}' https://localhost:8080/confluence/rest/api/content  | python -mjson.tool;

在使用嵌入宏创建页面时,根据请求有效负载中的定义,尚未设置任何宏参数。“URL”是宏的强制参数,但是我不清楚是否应该使用该元素,或者该元素(因此同时设置两者 - 无济于事)。

谢谢和问候, 安德鲁

标签: confluence-rest-apiconfluence-macros

解决方案


Confluence XHTML 内容负载需要如下所示:

<ac:structured-macro ac:name="iframe" ac:schema-version="1" ac:macro-id="f3b89c73-0096-409c-84fa-0158bf4e0f4f" xmlns:ac="http://www.atlassian.com/schema/confluence/4/ac/" xmlns:acxhtml="http://www.atlassian.com/schema/confluence/4/" xmlns:ri="http://www.atlassian.com/schema/confluence/4/ri/">
    <ac:parameter ac:name="src">
        <ri:url ri:value="https://example.com"/>
    </ac:parameter>
    <ac:parameter ac:name="width">100%</ac:parameter>
    <ac:parameter ac:name="height">750</ac:parameter>
    <ac:rich-text-body>
        <p>
            <br/>
        </p>
    </ac:rich-text-body>
</ac:structured-macro>

确定正确有效负载的最简单方法是使用宏手动创建页面并使用 REST API 检索 XHTML 内容片段

curl -u <user>:<password> -H 'Accept: application/json' --url 'https://<host:<port>/confluence/rest/api/content/<page-id>?expand=body.storage,version' | python -mjson.tool

推荐阅读