Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

rebecca.ingram December 13, 2021

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 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'
}
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
auth = (user, password)

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

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('.'):
resultpages.append(page)
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
TAGS
AUG Leaders

Atlassian Community Events