Hi there,
I am quickly hacking away on some dirty panel stuff with API calls. Specifically, I am calling APIs when the status of a blog post changes to “listed”. I do this by using a hook in the config.php:
'hooks' => [
'page.changeStatus:after' => function (Kirby\Cms\Page $newPage, Kirby\Cms\Page $oldPage) {
if($newPage->status() == "listed" && $newPage->includeInNewsletter() !== null){
$data = [
'name' => $newPage->slug(),
'type' => 'regular',
segments' => json_decode($newPage->includeInNewsletter(), true), // We want to convert the JSON into an associative array
'emails' => [
[
'subject' => $newPage->title()->toString(),
'from_name' => 'xxxxxxx',
'from' => 'office@xxxxxx.xxx',
'content' => snippet('newsletterNotification', ['article' => $newPage ], true)
]
]
];
$request = Remote::request('https://connect.xxxxxx.com/api/xxxxx', [
'method' => 'POST',
'headers' => [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer '.option('xxxxx.xxxxx')
],
'data' => json_encode($data),
]);
if ($response->code() != 200) {
throw new Exception('Error posting to xxxxx, please try again.');
}
}
Now, I get this error here in the panel, since obviously there was an error in the API request:
Now, the obvious thing to do is to check $data. But no matter what I do - die(), print_r(), var_dump() or any combination such as die(print_r($data)); the panel vanishes and there is redirect to a different URL showing this screen:
I get it. I am hacking really dirty in the panel. Okay. But please, I only need to see this variables output, fix the error and be done with it without installing xdebug or anything else complicated.
What am I doing wrong here?
Thanks
Andreas