How to set Header

In my “old” JSON API I simply send a Header like this:

header('Content-type: application/json; charset=utf-8');

In Kirby 3 this doesn’t work anymore. I have tried with this Link but without success … any simple solution expect of the content representation (also got no success with this)?

There is this way of stringing it to a response:

Things getting more nad more complicated … the Upgrade to K3 is really a hard and rocky way. Now the API works again but the Select field doesn’t show me any options.

I have given another try using a query, but seems that the query for the select field is ignoring the “not” Function?

    label: Interne Seite
    type: select
    options: query
    #api: api/?blocks=false
    query: site.index.not(site.index.filterBy("template","*=","block-")).sortBy("title","asc")

Edit: I’ve seen my API general doesn’t work anymore with the “not” function. Has this changed?

$exclude = $site->index()->filterBy('template','*=', 'block-');
$datas = $site->index()->not($exclude)->sortBy('title','asc');
foreach($datas as $data) {
  $json[(string)$data->url()] = (string)$data->title();
echo json_encode($json);

Could you post your code for the API please, so I can test that myself?

Please check the Top Post. I want to have a List with all Pages EXPECT of that which Template starts with “block-”. Worked like a charm in K2

This should work:

query: site.index.filterBy("template","!*=","block-").sortBy("title","asc")

That works :blush: but seems like the !*= is not documented? Check here:

But any Idea why the select field with the API isn’t working anymore?

Yes, the route doesn’t work because a route starting with api is protected in Kirby 3 and needs authentication.

You could fix that by prefixing the API string myapi/whatever

And yes, the filter is missing in the docs…

Have done a few tests, it’s also working with api as Slug. Problem was that the relative paths in the fetching not working anymore.


    label: Interne Seite
    type: select
    options: api
    api: api?blocks=false

This is working not anymore in K3, we have to use:

    label: Interne Seite
    type: select
    options: api
    api: "{{site.url}}/api?blocks=false"

Do you add the filter in the docs? Most pages in the docs have a “edit on github” button but not this one.

Strange, api doesn’t work for me :thinking:

Hmm strange, for me it’s working … but anyway, a long way but I’m more and more in :heart: with Kirby 3. Especially the query Syntax for the blueprints is sooooo awesome and useful!!

Yes, and you can even extend that with page models, custom page, file, field etc. methods and collections that can all be used in the query language.

Really amazing and saves a lot of time. In K2 I have created a simple field everytime when I want to fetch something from the site … and thanks so much for the amazing support!!! :smiling_face_with_three_hearts:

Done (and there are quite a few more now no longer hidden away in the source code, check out all these beauties)

1 Like

Amazing how much there are :slight_smile: