Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Python script to use Confluence API to get values from Page Properties

My request is quite similar to this one - I need to use the Confluence API to get metadata entered in multiple Confluence pages within a folder, except I'm writing a python script instead of using CQL.

I'm attempting to write a script that will scan all the pages (within the Operations Analytics folder, and within the embedded folders) for the Process Review date [and if the date has passed then the "Process Owner(s)" will receive an email.]

I can't figure out how to call the API to scan each individual page within the folder - I can only get the script to read the contents of a single page.

Someone provided an extremely helpful python script in this post that - unlike this script, I don't need to make updates to the pages in any way, I only need to get and read the data. I'm wondering if anyone can provide assistance with the script, or if anyone has written a similar script in Python to what I'm trying to accomplish? Thank you in advance.



Screenshot 2021-12-14 at 02.06.23.png

1 answer

0 votes
Dominic Lagger Community Leader Dec 13, 2021

Hi @rebecca_ingram 

I didn't wrote exactly what you need, but I could provide a snippet of my script.

This script would get the content of a single page:

import requests, json
import urllib3
import time
import getpass

url = 'URL'

user = 'USER' # input("Gibt dein Username an: ")
password = 'PW' # getpass.getpass("Gib dein Passwort an: ")

# -------------------------------------------------

headers = {
'X-Atlassian-Token': 'no-check',
'Content-Type': 'application/json'
auth = (user, password)

page = requests.get(url + '/rest/api/content/' + CONTENT_ID), auth=auth, verify=False).json()

I also wrote a little method to get all pages recursive:

url_request = self.url + '/rest/api/content/'+page_id+'/child/page'
pages = requests.get(url_request, auth=self.auth, verify=False).json()
for page in pages['results']:
if not page['title'].startswith('.'):
print("Seite '" + str(page['title']) + " ("+str(page['id'])+")' wurde zum Array hinzugefügt.")
self.getAllDescendantsWithIdRecursive(page['id'], resultpages)
return resultpages

Hope this helps a little bit.

Regards, Dominic

Suggest an answer

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

🏠 Say hello to the new Confluence Home!

Hi Atlassian Community, My name is DJ Chung, and I’m a Product Manager on the Confluence Cloud team. Today, I’m excited to share a new and improved version of Home. The new Home helps you ...

43,887 views 33 137
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