How to access content via api


#1

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

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


#3

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.


#4

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


#5

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!


#6

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
}


#7

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:


#8

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,… ?


#9

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


#10

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.


#11

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>