Missed Team ’24? Catch up on announcements here.

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

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

dsfds fdsfds March 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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

5 votes
Answer accepted
Aleks Yenin (Polontech)
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.
March 31, 2016

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

 

TAGS
AUG Leaders

Atlassian Community Events