Oli1
February 26, 2019, 5:20pm
#1
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)?
https://getkirby.com/docs/reference/tools/header/content-type
texnixe
February 26, 2019, 5:24pm
#2
There is this way of stringing it to a response:
I just remembered a change during the latest K3 betas. Bastian posted on Slack:
In order to fix this once and for all I’ve come up with a way to configure the response in your controllers or templates and cache that configuration with the page. This new implementation has a lot of nice side effects.
Here’s how it looks like in a controller for example if you want to change the content type, the response code and set some headers.
$kirby
->response()
->code(202)
->type('rss')
…
Oli1
February 26, 2019, 5:39pm
#3
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?
button_page_url:
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);
texnixe
February 26, 2019, 5:41pm
#4
Could you post your code for the API please, so I can test that myself?
Oli1
February 26, 2019, 5:43pm
#5
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
texnixe
February 26, 2019, 6:04pm
#6
Oli1:
button_page_url: label: Interne Seite type: select options: query #api: api/?blocks=false query: site.index.not(site.index.filterBy(“template”,"*=",“block-”)).sortBy(“title”,“asc”)
This should work:
query: site.index.filterBy("template","!*=","block-").sortBy("title","asc")
Oli1
February 26, 2019, 6:19pm
#7
That works but seems like the !*= is not documented? Check here:
https://getkirby.com/docs/reference/objects/pages/filter-by#available-filter-methods
But any Idea why the select field with the API isn’t working anymore?
texnixe
February 26, 2019, 6:27pm
#8
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…
Oli1
February 26, 2019, 6:36pm
#9
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.
K2
button_page_url:
label: Interne Seite
type: select
options: api
api: api?blocks=false
This is working not anymore in K3, we have to use:
button_page_url:
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.
texnixe
February 26, 2019, 6:42pm
#10
Strange, api
doesn’t work for me
Oli1
February 26, 2019, 6:49pm
#11
Hmm strange, for me it’s working … but anyway, a long way but I’m more and more in with Kirby 3. Especially the query Syntax for the blueprints is sooooo awesome and useful!!
texnixe
February 26, 2019, 6:51pm
#12
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.
Oli1
February 26, 2019, 6:53pm
#13
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!!!
texnixe
February 26, 2019, 8:57pm
#14
Done (and there are quite a few more now no longer hidden away in the source code, check out all these beauties )
1 Like
Oli1
February 27, 2019, 8:18am
#15
Amazing how much there are