如何通过REST API获取Confluence页面的所有版本

6

我想检索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号版本,但我不知道如何操作。
如果能帮我解决困境,我将不胜感激。 :)

目前似乎不可能实现。我刚在Atlassian的JIRA上为这个改进请求投了赞成票。你也可以投赞成票以引起注意。 - karailiev
2个回答

3

以下是一个示例:
请求:
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": ""
}
}

这将获取页面的所有版本和版本信息。


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']

这将为您提供页面的最新版本号。


答案只会得到最后一个和前一个,也就是说如果你有三个或以上,你将无法获得完整的响应 :( - Elazaron

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