Skip to content

Kirby 3.8.4

Introduction

Kirby's REST API is used by the Panel to connect between the Vue frontend and the PHP backend. It offers full access to your site, pages, files, users and more. You can use it for your SPA or mobile applications built on top of Kirby.

Endpoints

There are a large number of endpoints, split into the following areas:

Authentication

Every API request requires authentication. We offer session-based authentication or HTTP Basic auth. Read more ›

Language

In a multi-language site it is necessary to specify the language for which you want to use the API. This is done by sending an X-Language header containing the desired language code with your request.

Errors

Example error

{
    "status": "error",
    "message": "The page \"example\" cannot be found",
    "code": 404
}

In debug mode

When debug mode is activated in your config, you will get a more detailed error response with the exception type, file and line.

{
    "status": "error",
    "exception": "Exception",
    "message": "The page \"example\" cannot be found",
    "file": "config/api/data.php",
    "line": 46,
    "code": 500
}

To activate the debug mode, add the following to your config:

/site/config/config.php
return [
  'debug' => true
];

Please make sure to disable debug mode in production! Displaying PHP errors on a public server can be a serious security risk:

  • Error messages are displayed with detailed information about the code structure (e.g. file path, class, method)
  • With Whoops enabled, there will be even more detailed information about the code structure
  • Detailed error messages for login failures could leak information to attackers

In a production environment, always log errors to your PHP error logs.

Custom API location

Kirby can be configured to host the API at a different location. This can be set up in your config.

/site/config/config.php
return [
  'api' => [
    'slug' => 'rest'
  ]
];

All API endpoints are now available at https://yourdomain.com/rest. The Panel will automatically switch to the new API location.

Further customize the API

Find out how you can define custom endpoints, data functions, models etc. either via your config options › or in a plugin ›.