Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,297,440
Community Members
 
Community Events
165
Community Groups

Confluence API. How get page content with Python?

Hi,

I need to get the table from page in confluence and use it in Jupyter Notebook. I read the documentation https://developer.atlassian.com/server/confluence/confluence-rest-api-examples/ and tried using examples.

But when I run request 

params = (
('expand', 'body.storage'),
)
response = requests.get('https://wiki.tele2.ru/pages/rest/api/content/27691117', params=params, auth=('login', 'pass'))

I get empty response.

Can anyone help me?

2 answers

You may use the atlassian-python-api module from https://atlassian-python-api.readthedocs.io/confluence.html

use the confluence.get_page_by_id API (warning the html document has a typo for this API, it has no "self" parameter), make sure to set the expand parameter to "body.storage"


The API then returns d, a dictionary where the page view storage content is located in d['body']['storage']['value']

0 votes

Hi @Oleg Gonshtein 

Welcome to the Atlassian Community :)

I'm not the best with Python coding, but I believe I can help you.

Since you are using the requests library, I'm assuming you already installed it using pip.

The below script should get you the page contents.

import requests

contentApiUrl = '/rest/api/content'
# Change these based on your instance
confluenceBaseUrl = 'http://localhost:6740/c740'
pageId = '3309573'
username = 'admin'
password = 'admin'

requestUrl = '{confluenceBaseUrl}{contentApiUrl}/{pageId}?expand=body.storage'.format(confluenceBaseUrl = confluenceBaseUrl, contentApiUrl = contentApiUrl, pageId = pageId)
print requestUrl

requestResponse = requests.get(requestUrl, auth=(username, password))

print requestResponse.json()

 

A search for other Community posts will certainly find some more elaborated Python scripts, such as in this post.

 

I hope that helps.

Kind regards,
Thiago Masutti

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

39 views 0 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you