How can I get a list of standalone pages from API

I’m trying to use Kirby as a headless CMS, and I’d like to pre-render most pages, so at build time, I use the API to get all the pages.

Well, this is proving quite problematic. First of all, I’ve already had to manually code a recursive function to get subpages as well as top-level pages. That’s unfortunate.

But my biggest issue is that I’m not finding any way at all to get a list on standalone pages.

So, questions:

  • Are standalone pages not accessible via the API? Or did I perhaps simply not find that endpoint yet?
  • Is there not a single request I can make to the API that can respond with a full deeply nested list of all pages, subpages and standalone pages?

By standalone pages, do you mean pages at any level that do not have children? There are plenty of methods for checking these things.

There is code in the cookbook guide for getting the site tree, with or without subpages that might be useful.

That is PHP code… I’m trying to get this list from the API. Are you suggesting I make a custom API endpoint for this?

Not exactly. I mean pages that have no parent. They are not in the menu. But they can be reached if you know the URL.

For a nested list of all pages, you would indeed need a custom endpoint.

hmm, that’s unexpected.

Since Kirby is advertising its capacity of being used as a headless CMS, I expected this kind of feature to exist to make things easier.

Do you think this would make a good feature request?
Or perhaps this would make more sense as a plugin?

Also, the original question remains. Is there a way to get standalone pages from the API?

I don’t really see why that would mean that any possible endpoint is provided by the system, given that you can add any endpoint you want and totally customize it to your needs.

A single page is accessible via <code>GET</code> /api/pages/:id | Kirby CMS

Well, to be a headless CMS, you have to provide access to the content via the API.
Like you say, fetching a page whose ID you know is indeed supported out of the box.
But not being able to access the list of standalone pages via the API is definitely surprising and prohibitive in terms of a headless CMS…

In other words, a headless CMS whose API doesn’t answer the question “What pages are there?” out of the box is a surprise, at least to me.

@shawninder while most people are probably not using kirby fully headless if you search around you will find all kinds of plugins that help with this.

Kirby doesn’t give you everything out of the box but i think the power lies in the flexibility and ease of use to make your own. It’s more like toolkit for CMS than predefined CMS. That philosophy is everywhere. For example when you just install and look into Kirby Panel admin interface it will be empty - you have to do some work to use it. But it tends to be quick and pleasant work not some complicated mess.

Creating custom endpoint for pages will take very little time compared to the UI part for your site. But now you got superpower - you can make and use any endpoint with any data you want, wrap and cache other apis etc.