How to access content via api

Hi, in the example project provided I was wanted to access the notes content via the api but I canā€™t seem to find a way of doing that. Is it possible to access content via the api?

I was thinking it would be nice to use Kirby as an CMS but have a iOS app accessing the content via the api.

2 Likes

Have you checked the docs? https://getkirby.com/docs/guide/api/introduction

Hi, thank you for the quick reply. I have had a look at the docs. I couldnā€™t see what I was trying to achieve in there. Could it be I have to use a custom collection or model which is currently saying: Docs are coming soonā€¦?

Looking at the part which says:
$this->kirby();
$this->site();
$this->page($pageId);
$this->file($pageId, $filename);
$this->user($userId = null);
$this->users();

I was expecting one which said something like $this->content but could be way off.

2 Likes

All endpoints are available in the reference: https://getkirby.com/docs/reference

1 Like

I am having a similar question.
I am using the stock Starter Kit and trying to access the ā€˜Aboutā€™ page content using the API.

I followed the API documentation and use the following URL, I always receive Error 404:
http://localhost:8000/api/pages/project+about/

Am I doing something wrong? Thanks!

1 Like

Still canā€™t get to the bottom of it: In the Starter-Kit I can view this page in the browser:

http://localhost:8000/notes/exploring-the-universe

but I canā€™t get to it via the api:

Doing a get on this:
http://localhost:8000/api/pages/notes/

just returns:
{
ā€œstatusā€: ā€œerrorā€,
ā€œexceptionā€: ā€œExceptionā€,
ā€œmessageā€: ā€œNo route found for path: ā€œnotesā€ and request method: ā€œGETā€ā€,
ā€œfileā€: ā€œby/src/Http/Router.phpā€,
ā€œlineā€: 120,
ā€œcodeā€: 404
}

2 Likes

Anyone has solved out this issue? Experiencing the exact same issue here. A bit frustrated here, as I always receive the code 404 via API and I donā€™t think the docs are particularly helpful for this matter. :frowning:

i remember this being discussed on slack once. it might depens how your localhost setup is created and how authentification is done. have you tried uploading it to an apache/nginx server online?
can you tell us more about your localhost? mamp, xamp, php-router,ā€¦ ?

as you can see from the docs the 404 error is the generic error. have you tried enabling debug mode?

We didnā€™t manage to figure this out in the time we had been given to find a solution for a few upcoming projects in the office, so sadly we had to bounce on to Cockpit cms for those. Will follow this thread and hopefully get to use Kirby in the future for something.

hi, this is a proof of concept.
Is this what you are looking for? remember that you have to auteticarte to be able to connect to the API

  <main class="main" role="main">

<div class="app" id="app"> dfd</div>

<script>
     const csrf = "<?= csrf() ?>";

     fetch("<?php echo $kirby->url() ?>/api/roles", {
         method: "GET",
         headers: {
           "X-CSRF" : csrf
         }
       })
       .then(response => response.json())
       .then(response => {
         const page = response.data;
         console.log(page);

         


       })
       .catch(error => {
         // something went wrong
       });



   </script>