如何在 Confluence 中将一个页面附加为另一个页面的子页面 - REST API

How to attach a page as a child of another page in Confluence - REST API

我正在尝试使用 Confluence REST API 来更正 Confluence 站点上页面的树结构。我可以手动执行此操作,但是有很多页面,我已经在另一个 XML 文件中有了树结构。

目前我可以使用 confluence REST API 上传页面和图片。定义位于 here.

我尝试使用 /rest/api/content/{id} PUT 命令。这要求内容在请求的正文中。附上我从之前的 GET 请求中收到的内容,我发现我必须更新版本计数。

以上全部有效。但是似乎没有添加到祖先列表中。如果我将父页面添加到祖先列表中,我会收到格式错误报告。

如果我手动将该页面附加到另一个页面并请求其内容,我发现父级在祖先列表中出现了两次。历史计数也不会增加。

结果 JSON return 来自页面的 GET 请求:

http://someconfluencesite.com/rest/api/content/10031361?expand=ancestors (200)

{
    "id" : "10031361",
    "type" : "page",
    "title" : "Automatic Action Usage Updates",
    "ancestors" : [{
            "id" : "10031327",
            "type" : "page",
            "title" : "Action Lists"
        }, {
            "id" : "10031327",
            "type" : "page",
            "title" : "Action Lists"
        }, {
            "id" : "10031328",
            "type" : "page",
            "title" : "Actions Tab"
        }, {
            "id" : "10031327",
            "type" : "page",
            "title" : "Action Lists"
        }, {
            "id" : "10031327",
            "type" : "page",
            "title" : "Action Lists"
        }, {
            "id" : "10031328",
            "type" : "page",
            "title" : "Actions Tab"
        }
    ]
}

此树看起来如下所示:

这让我相信我使用了错误的命令。

我已尝试联系 Confluence 支持,但他们的授权电子邮件未到达我的收件箱。所以我来了:)

所以我的问题是在 confluence 中创建页面树的 REST 调用是什么?之后请求体的格式是什么?

编辑: 以下 PUT 请求获得成功的 return 代码。然而 returned 对象没有附加祖先(这并不罕见,因为在所有 GET 请求中,您必须展开才能获得它)。版本号不更新。这两个页面也没有相互挂钩。

{
     "id":"10552520",
     "type":"page",
     "title":"Correct Page Title",
     "ancestor":[
     {
         "id":"10552522",
         "type":"page"
     }],
     "version":
     {
          "number":"2"
     }
}

上面的好处是删除了页面的所有内容。

以下 POST 调用导致正在创建页面但没有祖先。祖先以提供的 id 存在。奇怪的是,这也是在页面中没有任何内容的情况下创建的。

{
    "type":"page",
    "title":"Correct Title",
    "space":{"key":"SpaceKey"},
    "ancestor":[{"id":"10553655","type":"page"}],
    "body":{"storage":{"value":"<p>New Page </p>","representation":"storage"}}
}

将以上内容放入 REST API 浏览器也会导致子项不附加到父项。

看来我的问题的答案就在问题本身。

JSON 需要 "ancestors" 而不是 "ancestor" 作为祖先数组的数组名称。更改后,所有内容都适用于 POST 请求。

因此,如果您阅读本文并遇到类似问题,请确保 JSON 中的所有元素名称都是正确的。如果不是,它们将被忽略。

{
    "id":"10552520",
    "type":"page",
    "title":"Correct Page Title",
    "ancestors":[
        {
            "id":"10552522",
            "type":"page"
        }
    ],
    "version":
        {
            "number":"2"
        }
    }

是"ancestors",不是"ancestor"。

要移动现有页面,请先获取其版本,space,等等。 然后用 version + 1, space, ancestors, title 调用 PUT。

pageaschild = { "type":"page",
      "title":name,
      "space":{"key":space},
      "ancestors":[{"id":ancestorid,"type":"page"}],
      "version":{"number":version}};

$.ajax({type:'PUT', url:baseURL + pageId, contentType:"application/json;charset=utf-8", data:JSON.stringify(pageaschild)});