【问题标题】:How to get all versions of Confluence page via REST API如何通过 REST API 获取所有版本的 Confluence 页面
【发布时间】:2015-06-03 04:08:48
【问题描述】:

我想在 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 上对这个 improvement request 投了赞成票。你也可以投票来吸引注意力。

标签: json api rest confluence


【解决方案1】:

这是一个例子:
请求:
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": ""
}
}

这将为您提供带有版本消息的页面的所有版本

【讨论】:

    【解决方案2】:

    我找到了获取版本号的方法。

    所以如果你去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']
    

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

    【讨论】:

    • 答案只得到最后一个和上一个,这意味着如果你有 3 个及以上,你将不会得到完整的响应:(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-27
    • 2015-05-23
    • 2017-03-10
    • 2016-12-25
    • 2017-05-09
    相关资源
    最近更新 更多