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?

dsfds fdsfds Mar 29, 2016

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

 

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Off-topic

Disney Live Action Reboots: Are you for or against?

Happy Friday Everyone! Today marks the international release of Disney's live action version of the animated classic Aladdin. I know that this movie was met with some controversy of over cast...

192 views 21 10
Join discussion

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