使用REST API更新Confluence页面

9
这是我目前拥有的代码,它可以创建一个新的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

这是我收到的错误信息。
{"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"}

这可能是权限错误。我知道我没有删除的权限。

3个回答

13

使用请求 /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

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
   }
}

请务必使用以下内容:

  • 在数据部分中使用内容ID
  • 在数据部分中使用版本号
  • 使用PUT请求
  • 在请求中使用内容ID

3
你知道为什么它会将页面移动到层次结构的根部,而不是保持在原地吗? - GregWringle
2
@GregWringle,经过一些试错和克服一些恼人的怪癖,以下方法对我有效: 在GET请求中使用'?expand=ancestors,space,version'。您将在响应中获得“ancestors”列表中的对象列表。使用该列表中的最后一个对象,并将其作为PUT请求中“ancestors”列表中的唯一对象。确保您拥有所有其他所需部分,例如页面ID、版本号等。如果您从GET响应中复制“ancestors”的整个值(对象列表)到PUT请求中,则无法正常工作! - iaswtw
@iaswtw 谢谢!这个方法可行,iaswtw。另外,我发现我不需要整个祖先对象:这个就足够了:page: { 'id':'2', ... 其他所有的东西 ... ancestors: [ { 'id':'1'} ]也就是说,我只需要祖先的ID,而不是整个庞大的东西 =) - Ryan S
我缺少了“表示”。 - specimen

0

有没有Bash的解决方案,可能吗? - MrPickles

0

尝试使用PUT而不是POST。

curl -v -u admin:admin -X PUT -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

产生 {"statusCode":500,"message":"javax.ws.rs.WebApplicationException: null"}。 - GregWringle

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接