Confluence集成实践:3:RestAPI集成方式

本文详细介绍了如何使用Confluence的REST API进行空间创建、内容管理和附件管理。首先,通过API创建空间,并进行事前、创建后的确认。接着,创建并确认内容,包括检查当前内容信息和创建新页面。最后,讨论了附件的添加及验证。文章提醒读者在使用REST API时注意官方文档中可能存在的路径和上下文问题。
摘要由CSDN通过智能技术生成

上篇文章介绍了Confluence提供的标准的RestAPI主要涵括在那些功能领域。在这篇文章中将会继续使用实际的例子来介绍如何使用这些RestAPI。

Rest Api

Confluence的相关RestAPI在上篇文章中进行了仔细的介绍,具体参看

项目 详细信息
Confluence RestAPI介绍 http://blog.csdn.net/liumiaocn/article/details/77814943

创建空间

Confluence的使用,一般项目从创建一个空间开始,所以第一步,使用Space相关的Api创建一个空间。

事前确认

使用Confluence的进行确认,目前只有两个space。
这里写图片描述
利用curl,使用Confluence提供的空间查询用的API也是得到一样的结果

[root@ku8-4 ~]# curl -u admin1:admin123 http://192.168.163.134:8090/rest/api/space 2>/dev/null |python -mjson.tool
{
    "_links": {
        "base": "http://192.168.163.134:8090",
        "context": "",
        "self": "http://192.168.163.134:8090/rest/api/space"
    },
    "limit": 25,
    "results": [
        {
            "_expandable": {
                "description": "",
                "homepage": "/rest/api/content/65547",
                "icon": "",
                "metadata": ""
            },
            "_links": {
                "self": "http://192.168.163.134:8090/rest/api/space/ds",
                "webui": "/display/ds"
            },
            "id": 98305,
            "key": "ds",
            "name": "Demonstration Space",
            "type": "global"
        },
        {
            "_expandable": {
                "description": "",
                "homepage": "/rest/api/content/65580",
                "icon": "",
                "metadata": ""
            },
            "_links": {
                "self": "http://192.168.163.134:8090/rest/api/space/SAM",
                "webui": "/display/SAM"
            },
            "id": 98306,
            "key": "SAM",
            "name": "SampleSpace",
            "type": "global"
        }
    ],
    "size": 2,
    "start": 0
}
[root@ku8-4 ~]# 

name:相关的项目记载着空间名称,可以看出目前只有两个,和图形界面取得的结果是一致的。

[root@ku8-4 ~]# curl -u admin1:admin123 http://192.168.163.134:8090/rest/api/space 2>/dev/null |python -mjson.tool |grep name
            "name": "Demonstration Space",
            "name": "SampleSpace",
[root@ku8-4 ~]# 

创建空间

API

curl -u admin1:admin123 -X POST -H ‘Content-Type: application/json’ -d’ {“key”: “TST”, “name”: “Example space”, “description”: { “plain”: { “value”: “This is an example space”, “representation”: “plain” } }, “metadata”: {}} ’ http://192.168.163.134:8090/rest/api/space

执行日志

[root@ku8-4 ~]# curl -u admin1:admin123 -X POST -H 'Content-Type: application/json' -d' {
  "key": "TST", "name": "Example space", "description": { "plain": { "value": "This is an example space", "representation": "plain" } }, "metadata": {}} ' http://192.168.163.134:8090/rest/api/space
{
  "id":98309,"key":"TST","name":"Example space","description":{
  "plain":{
  "value":"This is an example space","representation":"plain"},"_expandable":{
  "view":""}},"homepage":{
  "id":"65617","type":"page","status":"current","title":"Example space Home","extensions":{
  "position":"none"},"_links":{
  "webui":"/display/TST/Example+space+Home","edit":"/pages/resumedraft.action?draftId=65617","tinyui":"/x/UQAB","self":"http://192.168.163.134:8090/rest/api/content/65617"},"_expandable":{
  "container":"/rest/api/space/TST","metadata":"","operations":"","children":"/rest/api/content/65617/child","history":"/rest/api/content/65617/history","ancestors":"","body":"","version":"","descendants":"/rest/api/content/65617/descendant","space":"/rest/api/space/TST"}},"type":"global","_links":{
  "webui":"/display/TST","collection":"/rest/api/space","base":"http://192.168.163.134:8090","context":"","self":"http://192.168.163.134:8090/rest/api/space/TST"},"_expandable":{
  "metadata":"","icon":""}}[root@ku8-4 ~]#

创建后确认

[root@ku8-4 ~]# curl -u admin1:admin123 http://192.168.163.134:8090/rest/api/space 2>/dev/null |python -mjson.tool
{
    "_links": {
        "base": "http://192.168.163.134:8090",
        "context": "",
        "self": "http://192.168.163.134:8090/rest/api/space"
    },
    "limit": 25,
    "results": [
        {
            "_expandable": {
                "description": "",
                "homepage": "/rest/api/content/65547",
                "icon": "",
                "metadata": ""
            },
            "_links": {
                "self": "http://192.168.163.134:8090/rest/api/space/ds",
                "webui": "/display/ds"
            },
            "id": 98305,
            "key": "ds",
            "name": "Demonstration Space",
            "type": "global"
        },
        {
            "_expandable": {
                "description": "",
                "homepage": "/rest/api/content/65617",
                "icon": "",
                "metadata": ""
            },
            "_links": {
                "self": "http://192.168.163.134:8090/rest/api/space/TST",
                "webui": "/display/TST"
            },
            "id": 98309,
            "key": "TST",
            "name": "Example space",
            "type": "global"
        },
        {
            "_expandable": {
                "description": "",
                "homepage": "/rest/api/content/65580",
                "icon": "",
                "metadata": ""
            },
            "_links": {
                "self": "http://192.168.163.134:8090/rest/api/space/SAM",
                "webui": "/display/SAM"
            },
            "id": 98306,
            "key": "SAM",
            "name": "SampleSpace",
            "type": "global"
        }
    ],
    "size": 3,
    "start": 0
}
[root@ku8-4 ~]# 
[root@ku8-4 ~]# curl -u admin1:admin123 http://192.168.163.134:8090/rest/api/space 2>/dev/null |python -mjson.tool |grep name
            "name": "Demonstration Space",
            "name": "Example space",
            "name": "SampleSpace",
[root@ku8-4 ~]#

页面确认

这里写图片描述

确认group信息

[root@ku8-4 ~]# curl -u admin1:admin123 http://192.168.163.134:8090/rest/api/group 2>/dev/null |python -mjson.tool
{
    "_links": {
        "base": "http://192.168.163.134:8090",
        "context": "",
        "self": "http://192.168.163.134:8090/rest/api/group"
    },
    "limit": 200,
    "results": [
        {
            "_links": {
                "self": "http://192.168.163.134:8090/rest/experimental/group/confluence-administrators"
            },
            "name": "confluence-administrators",
            "type": "group"
        },
        {
            "_links": {
                "self": "http://192.168.163.134:8090/rest/experimental/group/confluence-users"
            },
            "name": "confluence-users",
            "type": "group"
        }
    ],
    "size": 2,
    "start": 0
}
[root@ku8-4 ~]#

确认用户信息

[root@ku8-4 ~]# curl -u admin1:admin123 http://192.168.163.134:8090/rest/api/user?username=admin 2>/dev/null |python -mjson.tool
{
    "_links": {
        "base": 
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值