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

Given a page, how can I retrieve all its child pages via the rest api?

Given a page, how can I retrieve all its child pages via the rest api?

 

Now I'm trying to do this but it doesn't work properly. It should return one child page, but it returns 20. Actually, it returns the pages on the same level of hierarachy as the parent page also. And also the parent pages of the parent page.

p1 = {"title": "parent page title"} 
  r1 = requests.get(config.SITE_URL + "/confluence/rest/api/content", params=p1, auth=(config.USERNAME, config.PASSWORD))

  pp_id = r1.json()["results"][0]["id"] # parent id


  # doesn't work properly
  

  # p2 = {"parent": pp_id}
  p2 = {"ancestors":[{"type": "page", "id": pp_id}]}
  # p2 = {}

 r2 = requests.get(config.SITE_URL + "/confluence/rest/api/content", params=p2, auth=(config.USERNAME, config.PASSWORD))

  # r2 = requests.get(config.SITE_URL + "/confluence/rest/api/content/" + str(pp_id), params=p2, auth=(config.USERNAME, config.PASSWORD))

  # r2 = requests.get(config.SITE_URL + "/confluence/rest/api/content/" + str(pp_id) +"?type=page&expand=descendant", params=p2, auth=(config.USERNAME, config.PASSWORD))

  # r2 = requests.get(config.SITE_URL + "/confluence/rest/api/content/" + str(pp_id) + "/descendant", params=p2, auth=(config.USERNAME, config.PASSWORD))

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

5 votes
Answer accepted

Hi,

Try the follwing, to get the parent id:

/rest/api/content/search?cql=title=<parentTitle>

If you only have the parents title, you need to send a second call first, to get the id from the title

/rest/api/content/search?cql=parent=<parentId>

Id and children cannot be found with /confluence/rest/api/content, so this is not going to work:

res = requests.get(BASE_URL + "/confluence/rest/api/content", params={"parent": "<parentId>"} , auth=("username", "pass")) 
res = requests.get(BASE_URL + "/confluence/rest/api/content", params={"title": "parents title"} , auth=("username", "pass"))

 

Community showcase
Published in Training & Certification

Introducing Atlassian University Live!

Atlassian University is committed to providing the best training and certification for Atlassian products through on-demand classes, in-person team training, a world-class certification program, and ...

292 views 8 16
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