Walking page tree via REST API

Paul Turner asked on August 3, 2022 01:31

The organization I'm working with is using Kentico 12. I am attempting to iterate through pages using the REST API. In other words, I'd like to start at the top of the folder hierarchy, retrieve a list of all child folders and pages, and iterate through each of the child folders and pages.

From the documentation, the only option I see for retrieving page is to specify the alias path, which must include the alias of all parent folders and the page itself. For example, from the documentation:

/content/currentsite/<culture>/document/<alias path>

and

/content/currentsite/en-us/document/company/careers

How do I get the alias path of a page via the API if I don't already know it? I can obviously get it through the administrative UI but that would be very tedious.

Thank you,

Paul

Recent Answers


Brenden Kehren answered on August 3, 2022 03:06

I'd highly recommend not doing this via the built-in REST API. I'd suggest just getting all of the content tree then in your code you're retrieving the data in iterate through it. Look at the parent node ID vs the path.

1 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on August 3, 2022 08:20

Hi Paul, I agree with Brenden, it's not recommended to use standard REST service for that. But it should be possible. In the documentation link you provided there is a section "Multiple pages" with exactly what you need.

You can retrieve child pages like this:

/content/currentsite/en-us/childrenof/news
1 votesVote for this answer Mark as a Correct answer

Paul Turner answered on August 4, 2022 11:36

@dmitry bastron and @brenden kehren, thank you both for your very quick response (and sorry for my slow response. It sounds like it is best for me to work directly from the database to retrieve page information. I appreciate the help.

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on August 4, 2022 11:43

@Paul, it also doesn't have to be a direct database query. You could write some app/service/whatever using Kentico API nuget packages to access this data efficiently, please refer to this doc article.

1 votesVote for this answer Mark as a Correct answer

Paul Turner answered on August 7, 2022 02:59

Thank you, @Dmitry Bastron

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.