上篇文章介绍了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":