KQL (Kirby Query Language)
Use KQL with bearer token authentication and enhanced features.
Kirby Query Language (KQL)
It is common to authenticate API requests with a token, which is not possible with the default KQL endpoint (/api/query
as defined by the official KQL plugin). To solve this problem, this plugin adds a new KQL endpoint under /api/kql
that supports the following features:
- Bearer token authentication
- Query response caching
- Multi-language support
To enable the bearer token authentication for KQL query requests to /api/kql
, set the following option in your config.php
:
config.php
return [
// Default to token-based authentication
'kql' => [
'auth' => 'bearer'
]
];
Now fetch the KQL query results as you normally would, but include an `Authentication' header with the bearer token in your request:
const response = await fetch("https://example.com/api/kql", {
method: "POST",
body: {
query: "site",
select: {
title: true,
photography: {
query: "page('photography').children",
select: ["title", "url"],
},
},
},
headers: {
Authorization: `Bearer ${process.env.KIRBY_API_TOKEN}`,
},
});
const data = await response.json();
console.log(data);