Skip to content

Instantly share code, notes, and snippets.

@juandesant
Last active September 22, 2022 14:42
Show Gist options
  • Save juandesant/6066c69a2aafd1223cb8859294fab9bd to your computer and use it in GitHub Desktop.
Save juandesant/6066c69a2aafd1223cb8859294fab9bd to your computer and use it in GitHub Desktop.
# Requires atlassian-python-api PyPI module
from atlassian import Confluence
# You should read your secret information some other way
your_confluence_url = "https://confluence.domain.tld"
your_username = "your_username"
your_password = "your_password"
# cf becomes the Confluence instance with the user logged in
cf = Confluence(
url = your_confluence_url,
username = your_username,
password = your_password
)
# We need a space in which to search for the page, and a title to search
your_head_page_space = "SPC" # This is the short name of the space
your_head_page_tile = "My page title with children pages to set" # Can include special characters
# get_page_by_title gives you the ID of the Confluence page that will be the parent of all immediate children
# we want changed; we are not doing a recursive search for additional children at other levels, but that might
# be easily achieved.
parent_page_id = cf.get_page_by_title(space=your_head_page_space, title=your_head_page_tile)
# Obtain all direct children to the page whose ID we found before
# We are assuming there are no more than 1000 children pages.
# For more children pages, we might need to check the result and paginate
# if need be.
target_pages = cf.get_page_child_by_type(parent_page_id, limit=1000, start=0)
# The `labels variable is a list of strings with the labels that we want to apply to these pages
labels = ["label1", "label2", "labeln"]
# And now we simply iterate first through the pages
for page in target_pages:
for label in labels: # and then for each label in labels
cf.set_page_label(page['id'], label) # The method does what it says in the tin
# Note that no exception management is done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment