Good evening,
for the past hour I tried to troubleshoot an on paper simple task to fetch data from an custom added api route inside a created panel section.
Inside the panel i added a method with following content:
const response = this $api.get(props.parent + "/poll-list");
console.log(response);
This issue is very confusion to me because every other api request got the x-csrf-header, even the custom request as well but whatever I do, I cannot get promising results. I added other parameters to the config like allowInsecure, basicAuth and other options but nothing worked so far…
I hope someone can help me here with this problem… thank you so much in advance!
Ah yes, by the way: I tried using different pattern/paths like just ‘/api/test’ which did not worked as well unfortunately. I tried using different kirby versions, everything without different results. window.panel.api.csrf and this.$api.csrf and everything else exists with a valid token
okay wow, this might be the stupidest error i’ve made in a while. Thank you. The problem layed in the response “Hello World”. I looked into the sourcecode of the kirby panel api request and noticed that it tried to look for “data” from the parsed JSON-Payload. Because I just used a text and not json there was the error “s is undefined” (from the compiled panel).
// panel/src/api/request.js
const { response } = await responder(request, await fetch(request));
let data = response.json;
// simplify the response
if (data.data && data.type === "model") {
data = data.data;
}
return data;
So yeah, all in all. Everything else worked just fine, it was just the wrong kind of payload. sorry…