# API

Kirby's REST API is used by the <abbr title="The Panel is Kirby's fast and powerful web interface to manage your website in the browser. The Panel is highly customizable in many ways for different project needs."><a href="https://getkirby.com/docs/glossary/#panel">Panel</a></abbr> to connect between the <abbr title="Vue is the JavaScript framework Kirby's admin Panel is built with."><a href="https://getkirby.com/docs/glossary/#vue">Vue</a></abbr> 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:

<nav class="auto-fill mb-12 text-sm" style="--min: 20rem; --gap: var(--spacing-1)">
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/api/auth" style="text-decoration: none">
		<strong class="block">Authentication</strong>
		/api/auth	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/api/languages" style="text-decoration: none">
		<strong class="block">Languages</strong>
		/api/languages	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/api/pages" style="text-decoration: none">
		<strong class="block">Pages</strong>
		/api/pages	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/api/roles" style="text-decoration: none">
		<strong class="block">Roles</strong>
		/api/roles	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/api/site" style="text-decoration: none">
		<strong class="block">Site</strong>
		/api/site	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/api/system" style="text-decoration: none">
		<strong class="block">System</strong>
		/api/system	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/api/translations" style="text-decoration: none">
		<strong class="block">Translations</strong>
		/api/translations	</a>
		<a class="block p-3 bg-light" href="https://getkirby.com/docs/reference/api/users" style="text-decoration: none">
		<strong class="block">Users</strong>
		/api/users	</a>
	</nav>

## Authentication

Every API request requires authentication. We offer session-based authentication or HTTP Basic auth. <a href="https://getkirby.com/docs/guide/api/authentication">Read more &rsaquo;</a>

If your frontend runs on a different origin, you likely need to use the <a href="https://getkirby.com/docs/reference/system/options/cors">`cors` option</a>.

## Language
In a <a href="https://getkirby.com/docs/guide/languages">multi-language site</a> 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

```js
{
    "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.

```js
{
    "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:

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

<warning>
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.
</warning>

## Custom API location

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

```php "/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 <a href="https://getkirby.com/docs/reference/system/options/api">config options &rsaquo;</a> or <a href="https://getkirby.com/docs/reference/plugins/extensions/api">in a plugin &rsaquo;</a>.