如何使用REST API将“PDF宏”插入现有的Confluence页面

时间:2015-11-13 19:08:48

标签: confluence-rest-api

我一直在尝试使用REST API将“PDF宏”插入Confluence页面,显然我遗漏了一些东西。我已经使用REST API成功创建了页面,并将PDF附加到页面上,但我很难理解我做错了什么。

curl -v -S -u user:password -X PUT -H 'Content-Type: application/json' -d'{"type":"page","body":{"storage":{"value":"<ac:structured-macro ac:name=\"viewpdf\"><ac:parameter ac:name=\"name\"><ri:attachment ri:filename=\"RequirementCoverageReport.pdf\"/><\/ac:parameter><ac:parameter ac:page=\"My Page\"<\/ac:parameter><\/ac:structured-macro>","representation":"storage", "container":{"type":"page","id":"78086157"}}}}' https://myurl/confluence/rest/api/content/78086157 | python -mjson.tool

以下是抛出的异常;

{
"message": "Edit Content id mismatch", 
"statusCode": 400
}

2 个答案:

答案 0 :(得分:0)

如果我用这个更新我的Confluence 5页面:

 <ac:structured-macro ac:name="viewpdf"><ac:parameter ac:name="name"><ri:attachment ri:filename="name_of_the_attached_pdf" /></ac:parameter></ac:structured-macro>

效果很好。但我只使用jQuery / Javascript。 如果您需要jQuery解决方案,请告诉我。

答案 1 :(得分:0)

我在尝试通过REST API更新页面内容时遇到了同样的错误。我通过将页面ID添加到JSON的根部分来解决它:

{
    "id": 12345, <---- this was missing
    "version": {
        "number": 3
    },
    "type": "page",
    "title": "New title",
    "body": {
        "storage": {
            "value": "<p>New text.</p>",
            "representation": "storage"
        }
    }
}

因此,在您的情况下,错过了新的版本号,并且页面ID应该移动到JSON的根部分。

相关问题