我想在Confluence中检索页面的所有版本。 REST API中有一个声称要返回历史记录的调用,但我没有运气。
/rest/api/content/{id}/history
当我打电话给我时,我会得到一个答案:
{"latest": true,
"createdBy": {
"type": "known",
"profilePicture": {
"path": "/confluence/s/en_GB/.../profilepics/Avatar-14.png",
"width": 48,
"height": 48,
"isDefault": false
},
"username": "first.last@abc123.com",
"displayName": "First Last",
"userKey": "userKey"
}, "createdDate": "2014-12-29T13:56:16.000+0100", "_links": {
"base": "https://host.abc123.net/confluence",
"context": "/confluence",
"self": "host.abc123.net/confluence/rest/api/content/12345678/history"
}, "_expandable": {
"lastUpdated": ""
}}
我知道此页面通过浏览器界面在历史记录中有17个版本。我似乎无法通过向查询添加任何类型的expand =来获取任何地方。
Confluence REST API的文档告诉我此调用应该:
返回内容历史记录的完整JSON表示
如果我转向“正常”REST API调用来检索内容,我可以在版本结构中得到一些关于历史记录的提示:
{"version": {
"by": {
"type": "known",
"profilePicture": {
"path": "/confluence/s/en_GB/5639/.../profilepics/default.png",
"width": 48,
"height": 48,
"isDefault": true
},
"username": "some.other@abc123",
"displayName": "Some Other",
"userKey": "userKeyGuidThingy"
},
"when": "2015-01-30T16:00:09.000+0100",
"message": "",
"number": 17,
"minorEdit": false
} }
我非常热衷于检索其他版本,数字1 - 16,但我看不出如何...
我非常感谢能帮助我解开的任何帮助.. :)
答案 0 :(得分:2)
这是一个例子:
要求:
http://localhost:8090/rest/experimental/content/7965952/version?expand=content
响应:
{
"results": [
{
"by": {
"type": "known",
"username": "admin",
"userKey": "40288ac65c33f555015c33fd0aed0000",
"profilePicture": {
"path": "/download/attachments/327681/user-avatar",
"width": 48,
"height": 48,
"isDefault": false
},
"displayName": "admin",
"_links": {
"self": "http://localhost:8090/rest/experimental/user?key=40288ac65c33f555015c33fd0aed0000"
}
},
"when": "2017-10-16T14:56:29.000+03:00",
"message": "more stuff",
"number": 6,
"minorEdit": false,
"hidden": false,
"content": {
"id": "7965952",
"type": "page",
"status": "current",
"title": "cla1",
"extensions": {
"position": "none"
},
"_links": {
"webui": "/display/S1/cla1",
"tinyui": "/x/AI15",
"self": "http://localhost:8090/rest/api/content/7965952"
},
"_expandable": {
"container": "/rest/api/space/S1",
"metadata": "",
"operations": "",
"children": "/rest/api/content/7965952/child",
"history": "/rest/api/content/7965952/history",
"ancestors": "",
"body": "",
"version": "",
"descendants": "/rest/api/content/7965952/descendant",
"space": "/rest/api/space/S1"
}
},
"_links": {
"self": "http://localhost:8090/rest/experimental/content/7965952/version/6"
}
},
{
"by": {
"type": "known",
"username": "admin",
"userKey": "40288ac65c33f555015c33fd0aed0000",
"profilePicture": {
"path": "/download/attachments/327681/user-avatar",
"width": 48,
"height": 48,
"isDefault": false
},
"displayName": "admin",
"_links": {
"self": "http://localhost:8090/rest/experimental/user?key=40288ac65c33f555015c33fd0aed0000"
}
},
"when": "2017-10-16T14:56:12.000+03:00",
"message": "stuff",
"number": 5,
"minorEdit": false,
"hidden": false,
"content": {
"id": "7965952",
"type": "page",
"status": "historical",
"title": "cla1",
"extensions": {
"position": "none"
},
"_links": {
"webui": "/pages/viewpage.action?pageId=7965962",
"tinyui": "/x/Co15",
"self": "http://localhost:8090/rest/api/content/7965952?status=historical&version=5"
},
"_expandable": {
"container": "",
"metadata": "",
"operations": "",
"children": "/rest/api/content/7965952/child?parentVersion=5",
"history": "/rest/api/content/7965952/history",
"ancestors": "",
"body": "",
"version": "",
"descendants": "/rest/api/content/7965952/descendant",
"space": "/rest/api/space/S1"
}
},
"_links": {
"self": "http://localhost:8090/rest/experimental/content/7965952/version/5"
}
},
{
"by": {
"type": "known",
"username": "admin",
"userKey": "40288ac65c33f555015c33fd0aed0000",
"profilePicture": {
"path": "/download/attachments/327681/user-avatar",
"width": 48,
"height": 48,
"isDefault": false
},
"displayName": "admin",
"_links": {
"self": "http://localhost:8090/rest/experimental/user?key=40288ac65c33f555015c33fd0aed0000"
}
},
"when": "2017-10-16T14:39:28.000+03:00",
"message": "",
"number": 4,
"minorEdit": false,
"hidden": false,
"content": {
"id": "7965952",
"type": "page",
"status": "historical",
"title": "cla1",
"extensions": {
"position": "none"
},
"_links": {
"webui": "/pages/viewpage.action?pageId=7965961",
"tinyui": "/x/CY15",
"self": "http://localhost:8090/rest/api/content/7965952?status=historical&version=4"
},
"_expandable": {
"container": "",
"metadata": "",
"operations": "",
"children": "/rest/api/content/7965952/child?parentVersion=4",
"history": "/rest/api/content/7965952/history",
"ancestors": "",
"body": "",
"version": "",
"descendants": "/rest/api/content/7965952/descendant",
"space": "/rest/api/space/S1"
}
},
"_links": {
"self": "http://localhost:8090/rest/experimental/content/7965952/version/4"
}
},
{
"by": {
"type": "known",
"username": "admin",
"userKey": "40288ac65c33f555015c33fd0aed0000",
"profilePicture": {
"path": "/download/attachments/327681/user-avatar",
"width": 48,
"height": 48,
"isDefault": false
},
"displayName": "admin",
"_links": {
"self": "http://localhost:8090/rest/experimental/user?key=40288ac65c33f555015c33fd0aed0000"
}
},
"when": "2017-10-16T14:39:12.000+03:00",
"message": "",
"number": 3,
"minorEdit": false,
"hidden": false,
"content": {
"id": "7965952",
"type": "page",
"status": "historical",
"title": "cla1",
"extensions": {
"position": "none"
},
"_links": {
"webui": "/pages/viewpage.action?pageId=7965959",
"tinyui": "/x/B415",
"self": "http://localhost:8090/rest/api/content/7965952?status=historical&version=3"
},
"_expandable": {
"container": "",
"metadata": "",
"operations": "",
"children": "/rest/api/content/7965952/child?parentVersion=3",
"history": "/rest/api/content/7965952/history",
"ancestors": "",
"body": "",
"version": "",
"descendants": "/rest/api/content/7965952/descendant",
"space": "/rest/api/space/S1"
}
},
"_links": {
"self": "http://localhost:8090/rest/experimental/content/7965952/version/3"
}
},
{
"by": {
"type": "known",
"username": "admin",
"userKey": "40288ac65c33f555015c33fd0aed0000",
"profilePicture": {
"path": "/download/attachments/327681/user-avatar",
"width": 48,
"height": 48,
"isDefault": false
},
"displayName": "admin",
"_links": {
"self": "http://localhost:8090/rest/experimental/user?key=40288ac65c33f555015c33fd0aed0000"
}
},
"when": "2017-10-16T14:38:36.000+03:00",
"message": "",
"number": 2,
"minorEdit": false,
"hidden": false,
"content": {
"id": "7965952",
"type": "page",
"status": "historical",
"title": "cla1",
"extensions": {
"position": "none"
},
"_links": {
"webui": "/pages/viewpage.action?pageId=7965957",
"tinyui": "/x/BY15",
"self": "http://localhost:8090/rest/api/content/7965952?status=historical&version=2"
},
"_expandable": {
"container": "",
"metadata": "",
"operations": "",
"children": "/rest/api/content/7965952/child?parentVersion=2",
"history": "/rest/api/content/7965952/history",
"ancestors": "",
"body": "",
"version": "",
"descendants": "/rest/api/content/7965952/descendant",
"space": "/rest/api/space/S1"
}
},
"_links": {
"self": "http://localhost:8090/rest/experimental/content/7965952/version/2"
}
},
{
"by": {
"type": "known",
"username": "admin",
"userKey": "40288ac65c33f555015c33fd0aed0000",
"profilePicture": {
"path": "/download/attachments/327681/user-avatar",
"width": 48,
"height": 48,
"isDefault": false
},
"displayName": "admin",
"_links": {
"self": "http://localhost:8090/rest/experimental/user?key=40288ac65c33f555015c33fd0aed0000"
}
},
"when": "2017-10-16T14:23:14.000+03:00",
"message": "",
"number": 1,
"minorEdit": false,
"hidden": false,
"content": {
"id": "7965952",
"type": "page",
"status": "historical",
"title": "cla1",
"extensions": {
"position": "none"
},
"_links": {
"webui": "/pages/viewpage.action?pageId=7965955",
"tinyui": "/x/A415",
"self": "http://localhost:8090/rest/api/content/7965952?status=historical&version=1"
},
"_expandable": {
"container": "",
"metadata": "",
"operations": "",
"children": "/rest/api/content/7965952/child?parentVersion=1",
"history": "/rest/api/content/7965952/history",
"ancestors": "",
"body": "",
"version": "",
"descendants": "/rest/api/content/7965952/descendant",
"space": "/rest/api/space/S1"
}
},
"_links": {
"self": "http://localhost:8090/rest/experimental/content/7965952/version/1"
}
}
],
"start": 0,
"limit": 100,
"size": 6,
"_links": {
"self": "http://localhost:8090/rest/experimental/content/7965952/version?expand=content",
"base": "http://localhost:8090",
"context": ""
}
}
这将为您提供包含版本消息的页面的所有版本
答案 1 :(得分:0)
我找到了获取版本号的方法。
所以如果你去https://confluence.yourdomain.com/rest/api/content/page_id(1234567)/history。您将获得以下json响应。
{
"previousVersion":{
"by":{
"type":"known",
"profilePicture":{
"path":"image/path",
"width":48,
"height":48,
"isDefault":true
},
"username":"username",
"displayName":"password",
"userKey":"userkey"
},
"when":"date-time",
"message":"",
"number":1,
"minorEdit":false
},
"lastUpdated":{
"by":{
"type":"known",
"profilePicture":{
"path":"image/path",
"width":48,
"height":48,
"isDefault":true
},
"username":"username",
"displayName":"password",
"userKey":"userkey"
},
"when":"date-time",
"message":"",
"number":2,
"minorEdit":false
},
"latest":true,
"createdBy":{
"type":"known",
"profilePicture":{
"path":"image/path",
"width":48,
"height":48,
"isDefault":true
},
"username":"username",
"displayName":"password",
"userKey":"userkey"
},
"createdDate":"userkey",
"_links":{
"base":"https://confluence.yourdomain.com",
"context":"",
"self":"https://confluence.yourdomain.com/rest/api/content/page_id/history"
}
}
从该响应中,json只需获取版本号取决于您使用的脚本语言。对于Python,下面这段代码将获取版本号。
version=requests.get(https://confluence.yourdomain.com/rest/api/content/page_id(1234567)/history)
version= version.json()
print version['lastUpdated']['number']
这将为您提供该页面的最新版本号。