使用REST API在Confluence中更新页面

Gre*_*gle 4 jira confluence jira-rest-api confluence-rest-api

这就是我目前所获得的,它创建了一个新的Confluence页面.它没有更新它.它也将它发布在根空间中TST,但我希望它在TST/space1/subsection2/updateThisPage.

curl -v -u admin:admin -X POST -H Content-Type: application/json -d  "{\"id\":\"123456\",\"type\":\"page\",\"title\":\"new page\",\"space\":{\"key\":\"TST\",\"title\":\"updateThisPage\"},\"body\":{\"storage\":{\"value\":\"<p>This is the updated text for the new page</p>\",\"representation\":\"storage\"}},\"version\":{\"number\":3}}" http://localhost:8090/rest/api/content?spaceKey=TST&title=updateThisPage
Run Code Online (Sandbox Code Playgroud)

这是我收到的错误消息

{"statusCode":400,"message":"A page with this title already exists: A page already exists with the title new page in the space with key TST"}
Run Code Online (Sandbox Code Playgroud)

会是权限错误吗?我知道我无权删除.

The*_*olC 8

使用request/rest/api/content/{id}.

这对我有用.

curl -u admin:admin -X PUT -H "Content-Type: application/json" -d "{\"id\":\"26738701\",\"type\":\"page\",\"title\":\"new page\",\"space\":{\"key\":\"RO\"},\"body\":{\"storage\":{\"value\":\"<p>UPDATE This is a new page</p>\",\"representation\":\"storage\"}},\"version\":{\"number\":2}}" http://localost:10080/rest/api/content/26738701
Run Code Online (Sandbox Code Playgroud)

JSON有效载荷:

{  
   "id":"26738701",
   "type":"page",
   "title":"new page",
   "space":{  
      "key":"RO"
   },
   "body":{  
      "storage":{  
         "value":"<p>UPDATE This is a new page</p>",
         "representation":"storage"
      }
   },
   "version":{  
      "number":2
   }
}
Run Code Online (Sandbox Code Playgroud)

别忘了使用:

  • 数据部分中的内容ID
  • 数据部分中的版本号
  • PUT请求
  • 请求中的内容ID

  • @GregWringle,经过一番尝试和错误并解决了一些烦人的怪癖之后,以下方法对我有用:在 GET 请求中使用 '?expand=ancestors,space,version' 。您将在响应中获得“祖先”中的对象列表。使用该列表中的*最后一个*对象,并将其作为 PUT 请求中“祖先”列表中的*唯一*对象。确保您像以前一样拥有所有其他必需的部分,例如页面 ID、版本号等。如果将 GET 响应中“祖先”的整个值(对象列表)复制到 PUT 请求中,它将不起作用! (3认同)
  • 你知道为什么它将页面移动到层次结构的根目录而不是保持它的位置吗? (2认同)