Atlassian Confluence REST API Making request and keep the session (Eng)

In this topic I’ll show you how to make session to Atlassian Confluence with python requests and keep it in memory.

Atlassian Confluence

Based on:

For someone who found this topic by “search machines”, there is some more detailed how-to – probably can help you:

Python requests module:

At first you should know and understand how requests works, basically.

Check how your confluence works:

Next – you should know the point, where is your Confluence server make authorisation, in my situation it lies here (this is looks cozy, but this is our company’s way. In your situation it can be simpler, as documented in links above):

Then you compose a request like:

This will execute and save the session in memory, so you will not need to authorise each next request.

REST URL composing:

Then you compose the needed URL like it shown here:

This will be useful to create this (in KB):

Create content
POST /rest/api/content
Get content
GET /rest/api/content
PUT /rest/api/content/{contentId}
Get content by id
GET /rest/api/content/{id}
DELETE /rest/api/content/{id}

Session execute:

When you have all needed arguments and space id and parent-child pages of Atlassian Confluence, you can simply add them as like it shown in example above and execute:

In this example you pick up the session stored in memory and just send any needed URL request, then json decode the answer and shows the result. You can do it as many times as you need, the session is open and ready to get and post.

Sometimes its better, than send credentials each time when you GET\POST something.

This example will show all spaces for current user in Atlassian Confluence, then show all pages on it, and all child items with theirs id, title, web link etc.



About trianglesis

Александр Брюндтзвельт - гений, филантроп, 100 гривен в кармане. Этот блог - "сток" моих мыслей и заметок. Достаточно одного взгляда на него, чтобы понять, что такой же бардак творится у меня в голове. Если вам этот бардак интересен - милости прошу.
Bookmark the permalink.