...
Just my blog

Blog about everything, mostly about tech stuff I made. Here is the list of stuff I'm using at my blog. Feel free to ask me about implementations.

Soft I recommend
Py lib I recommend

I'm using these libraries so you can ask me about them.

Atlassian Confluence REST API Logic structure (Eng)

Read this article after you know how to make REST API request to Atlassian Confluence! atlassian_con This topic will show you some part of internal scheme of Confluence API and hierarchy. Based on:

So, looking on the Confluence docs all this scheme looks like well-structured logical system, but it has some difficulties, just as for me. Before you POST of GET something will be better if you make a probing GET request to see the whole structure in your organisation. In this example you will get those arguments:

# Confluence stats
space_page = '625685389'
space_root_page = '625685397'
space_id = '624689178'
space_key = '~configipedia_service_account'
space_name = 'DocBot+space'
child_page_1 = '625685424'
child_page_2 = '625685428'
confPedia_root = 'https://docs.YOURCOMPANYMAME.com'
confPediaUser = '~configipedia_service_account'

# api keys
# Usage example: "confPedia_root+conf_content+space_id" - request to get space homepage content
api = '/rest/api/'
conf_space = '/rest/api/space/'
conf_content = '/rest/api/content/'
conf_children = '/child/page/'

 

# Confluence stats

space_page = This is the page of your Confluence account. Check if was created, sometimes new account have no space. space_root_page = This is the home page, where you can add widgets, history and etc. Add there a widget with history of all pages created, then you will see when something was posted successfully. space_id = this is ID of space, not the page on it, just the account's space. space_key = '~configipedia_service_account' - this is a name of your service account, this option can show you the space in request like:  https://docs.bmc.com/docs/rest/api/space/~configipediaautomation space_name = 'DocBot+space' - just a space name. child_page_1 = this is a previously created child page, attached to account space. Just for test purposes. I recommend you to create them to see how it works. child_page_2 = see above. confPedia_root = here all you request sentences will starts. confPedia_root/rest/api/... confPediaUser = your automation user.

# api keys

# Usage example: "confPedia_root+conf_content+space_id" - request to get space homepage content api = '/rest/api/' conf_space = '/rest/api/space/' conf_content = '/rest/api/content/' conf_children = '/child/page/' After you make this recognition, you should collect all needed arguments: accounts, page ids, space ids - and then you can just compose any path where you want to post topic or file. Make sure that service account have rights to post anywhere else except its own space! You should know where is space of currently automated account lies: Here GET and answer examples:

GET THE SPACE:

https://docs.YOURCOMPANYMAME.com/docs/rest/api/space/~configipedia_service_account

{
	"id": 624689178,
	"key": "~configipedia_service_account",
	"name": "Configipedia Automation",
	"type": "global",
	"_links": {
		"collection": "/rest/api/space",
		"base": "https://docs.YOURCOMPANYMAME.com/docs",
		"context": "/docs",
		"self": "https://docs.YOURCOMPANYMAME.com/docs/rest/api/space/~configipedia_service_account"
	},
	"_expandable": {
		"icon": "",
		"description": "",
		"homepage": "/rest/api/content/625685389"
	}
}

GET SPACE CONTENT HOME PAGE:

https://docs.YOURCOMPANYMAME.com/docs/rest/api/content/625685389 [su_spoiler title="Code" icon="chevron"]

{
	"id": "625685389",
	"type": "page",
	"status": "current",
	"title": "DocBot homepage",
	"space": {
		"id": 624689178,
		"key": "~configipedia_service_account",
		"name": "Configipedia SVC",
		"type": "global",
		"_links": {
			"self": "https://docs.YOURCOMPANYMAME.com/docs/rest/api/space/~configipedia_service_account"
		},
		"_expandable": {
			"icon": "",
			"description": "",
			"homepage": "/rest/api/content/625685389"
		}
	},
	"history": {
		"latest": true,
		"createdBy": {
			"type": "known",
			"profilePicture": {
				"path": "/docs/s/en_GB/5983/f3e491afc761ac0a6981cfa3dcbc04fc7e88c149.36/_/images/icons/profilepics/default.png",
				"width": 48,
				"height": 48,
				"isDefault": true
			},
			"username": "configipedia_service_account",
			"displayName": "Configipedia SVC",
			"userKey": "SOME_KEY"
		},
		"createdDate": "2016-02-17T04:07:48.938-06:00",
		"_links": {
			"self": "https://docs.YOURCOMPANYMAME.com/docs/rest/api/content/625685389/history"
		},
		"_expandable": {
			"lastUpdated": "",
			"previousVersion": "",
			"nextVersion": ""
		}
	},
	"version": {
		"by": {
			"type": "known",
			"profilePicture": {
				"path": "/docs/s/en_GB/5983/f3e491afc761ac0a6981cfa3dcbc04fc7e88c149.36/_/images/icons/profilepics/default.png",
				"width": 48,
				"height": 48,
				"isDefault": true
			},
			"username": "configipedia_service_account",
			"displayName": "Configipedia SVC",
			"userKey": "SOME_KEY"
		},
		"when": "2016-02-17T04:09:43.482-06:00",
		"message": "",
		"number": 2,
		"minorEdit": false
	},
	"extensions": {
		"position": "none"
	},
	"_links": {
		"webui": "/display/~configipedia_service_account/DocBot+homepage",
		"tinyui": "/x/jTNLJQ",
		"collection": "/rest/api/content",
		"base": "https://docs.YOURCOMPANYMAME.com/docs",
		"context": "/docs",
		"self": "https://docs.YOURCOMPANYMAME.com/docs/rest/api/content/625685389"
	},
	"_expandable": {
		"container": "",
		"metadata": "",
		"operations": "",
		"children": "/rest/api/content/625685389/child",
		"ancestors": "",
		"body": "",
		"descendants": "/rest/api/content/625685389/descendant"
	}
}

[/su_spoiler]

GET HOME PAGE CHILD ITEMS CONTENT

https://docs.YOURCOMPANYMAME.com/docs/rest/api/content/625685397 [su_spoiler title="Code" icon="chevron"]

{
	"id": "625685397",
	"type": "page",
	"status": "current",
	"title": "Home page DocBot (Parent 1)",
	"space": {
		"id": 624689178,
		"key": "~configipedia_service_account",
		"name": "Configipedia SVC",
		"type": "global",
		"_links": {
			"self": "https://docs.YOURCOMPANYMAME.com/docs/rest/api/space/~configipedia_service_account"
		},
		"_expandable": {
			"icon": "",
			"description": "",
			"homepage": "/rest/api/content/625685389"
		}
	},
	"history": {
		"latest": true,
		"createdBy": {
			"type": "known",
			"profilePicture": {
				"path": "/docs/s/en_GB/5983/f3e491afc761ac0a6981cfa3dcbc04fc7e88c149.36/_/images/icons/profilepics/default.png",
				"width": 48,
				"height": 48,
				"isDefault": true
			},
			"username": "configipedia_service_account",
			"displayName": "Configipedia SVC",
			"userKey": "SOME_KEY"
		},
		"createdDate": "2016-02-17T04:11:21.303-06:00",
		"_links": {
			"self": "https://docs.YOURCOMPANYMAME.com/docs/rest/api/content/625685397/history"
		},
		"_expandable": {
			"lastUpdated": "",
			"previousVersion": "",
			"nextVersion": ""
		}
	},
	"version": {
		"by": {
			"type": "known",
			"profilePicture": {
				"path": "/docs/s/en_GB/5983/f3e491afc761ac0a6981cfa3dcbc04fc7e88c149.36/_/images/icons/profilepics/default.png",
				"width": 48,
				"height": 48,
				"isDefault": true
			},
			"username": "configipedia_service_account",
			"displayName": "Configipedia SVC",
			"userKey": "SOME_KEY"
		},
		"when": "2016-02-17T04:24:25.481-06:00",
		"message": "",
		"number": 3,
		"minorEdit": false
	},
	"extensions": {
		"position": "none"
	},
	"_links": {
		"webui": "/pages/viewpage.action?pageId=625685397",
		"tinyui": "/x/lTNLJQ",
		"collection": "/rest/api/content",
		"base": "https://docs.YOURCOMPANYMAME.com/docs",
		"context": "/docs",
		"self": "https://docs.YOURCOMPANYMAME.com/docs/rest/api/content/625685397"
	},
	"_expandable": {
		"container": "",
		"metadata": "",
		"operations": "",
		"children": "/rest/api/content/625685397/child",
		"ancestors": "",
		"body": "",
		"descendants": "/rest/api/content/625685397/descendant"
	}
}

[/su_spoiler]

GET CHILD ITEMS FROM PARENT:

https://docs.YOURCOMPANYMAME.com/docs/rest/api/content/625685397/child/page [su_spoiler title="Code" icon="chevron"]

{
	"results": [{
		"id": "625685428",
		"type": "page",
		"status": "current",
		"title": "Child 2",
		"extensions": {
			"position": "none"
		},
		"_links": {
			"webui": "/display/~configipedia_service_account/Child+2",
			"tinyui": "/x/tDNLJQ",
			"self": "https://docs.YOURCOMPANYMAME.com/docs/rest/api/content/625685428"
		},
		"_expandable": {
			"container": "",
			"metadata": "",
			"operations": "",
			"children": "/rest/api/content/625685428/child",
			"history": "/rest/api/content/625685428/history",
			"ancestors": "",
			"body": "",
			"version": "",
			"descendants": "/rest/api/content/625685428/descendant",
			"space": "/rest/api/space/~configipedia_service_account"
		}
	},
	{
		"id": "625685424",
		"type": "page",
		"status": "current",
		"title": "One more manual created page (Child 1)",
		"extensions": {
			"position": "none"
		},
		"_links": {
			"webui": "/pages/viewpage.action?pageId=625685424",
			"tinyui": "/x/sDNLJQ",
			"self": "https://docs.YOURCOMPANYMAME.com/docs/rest/api/content/625685424"
		},
		"_expandable": {
			"container": "",
			"metadata": "",
			"operations": "",
			"children": "/rest/api/content/625685424/child",
			"history": "/rest/api/content/625685424/history",
			"ancestors": "",
			"body": "",
			"version": "",
			"descendants": "/rest/api/content/625685424/descendant",
			"space": "/rest/api/space/~configipedia_service_account"
		}
	}],
	"start": 0,
	"limit": 25,
	"size": 2,
	"_links": {
		"self": "https://docs.YOURCOMPANYMAME.com/docs/rest/api/content/625685397/child/page",
		"base": "https://docs.YOURCOMPANYMAME.com/docs",
		"context": "/docs"
	}
}

[/su_spoiler]