Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to call an API via blueprint #63

Closed
gryzzly opened this issue Jan 22, 2022 · 3 comments
Closed

How to call an API via blueprint #63

gryzzly opened this issue Jan 22, 2022 · 3 comments
Assignees

Comments

@gryzzly
Copy link

gryzzly commented Jan 22, 2022

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!

@gryzzly
Copy link
Author

gryzzly commented Jan 23, 2022

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!

@bnomei
Copy link
Owner

bnomei commented Apr 6, 2022

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',
        ];
    },
  ],
];

https://github.com/thathoff/kirby-git-content/blob/72e079438e0af861a75074d95c7ee24643bff5f9/src/KirbyGit.php#L41

maybe @thathoff could add some return status values to the helpers push and pull methods.

@thathoff
Copy link

thathoff commented Apr 6, 2022

Great idea, thanks @bnomei. That seems like a good Idea, i’ve just created an issue for this.

PS: @gryzzly we’ve started working on a Panel Area (supported since kirby 3.6) with push and pull buttons. You can try this by using the panel branch (or dev-panel version if you use composer).

@bnomei bnomei closed this as completed Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants