How to call an API via blueprint
gryzzly opened this issue · comments
Hey, I’m using this plugin: https://github.com/thathoff/kirby-git-content which creates an endpoint like /git-content/push
and I’d like to add a button in site.yml
that calls that endpoint.
This example https://github.com/bnomei/kirby3-janitor/wiki/Example:-Trigger-jons-with-JS-and-Panel-Vue shows how to call endpoints but I am not sure where would I place this code. Can you advice?
Thanks!
Hey, got a little bit more further, I‘m trying to call the git endpoint like this:
in config.php:
'bnomei.janitor.jobs' => [
'contentPush' => function (Kirby\Cms\Page $page = null, string $data = null) {
// $page => page object where the button as pressed
$kirby->call('/git-content/push?secret=foobar');
return [
'status' => 200,
'label' => $page->title() . ' ' . $data,
];
},
],
'thathoff' => [
'git-content' => [
'commit' => true,
'cronHooksEnabled' => true,
'cronHooksSecret' => 'foobar',
'displayErrors' => true
],
]
But pressing the button is always showing a dialog saying: No route found for path: "git-content/push" and request method: "GET"
.
However, I can see that the route is indeed installed at http://localhost:8000/git-content/push
– if I visit it I receive the appropriate error message in JSON like this:
{"status":"forbidden","message":"Invalid secret passed"}
Do you see something obviously wrong with what I am doing?
Thanks!
Since the lib you are using is exposing simple helper calls to routes you could just call them manually.
'bnomei.janitor.jobs' => [
'contentPush' => function (Kirby\Cms\Page $page = null, string $data = null) {
// $page => page object where the button as pressed
$git = new \Thathoff\GitContent\KirbyGitHelper();
$status = $git->push(); // does not work yet
$status = true;
return [
'status' => status ? 200 : 204,
'label' => 'Pushed content',
];
},
],
];
maybe @thathoff could add some return status values to the helpers push
and pull
methods.