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

4 votes
Accepted answer

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"))

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published yesterday in Agile

How Scrum works? It starts with training and education

To answer “How scrum works,” most of the teams I've worked with first addressed the question: “where to start?”  That question applies to both implementation and improvements on the Scrum framew...

169 views 3 5
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you