spinen / laravel-clickup

SPINEN's Laravel Package for ClickUp.
28 stars 14 forks source link

Help with Laravel Workflow #27

Closed Ceepster14 closed 3 years ago

Ceepster14 commented 3 years ago

Hi,

I'm interested in using this package for a ClickUp integration in a Laravel app I'm working on, but I'm struggling a little to understand the correct flow (in a Laravel context) for creating a webhook.

I've followed the installation and setup instructions and have associated the API access token with a user. I can use this successfully to read information out of ClickUp such as teams etc.

As part of the application I need to create a webhook so the application can respond to various events in ClickUp.

My intial thought was to create a new instance of Spinen\ClickUp\Webhook, then set the required properties (endpoint, team_id, events) and then save the instance. However, this generates a Spinen\ClickUp\Exceptions\NoClientException which is kind of understandable as my access token is associated with a User. However (in a Laravel context) I can't see how to go from an instance of the User with the token to then creating a Webhook.

Is it possible you could provide an example to demonstrate the correct workflow?

Thanks

ssfinney commented 3 years ago

Hey @Ceepster14!

Yeah, I just reproduced what you were referring to and it's a bug. And that's not the only problem--if the webhook becomes "unhealthy" there isn't a Laravel-y way to set that back to healthy. I ran into this on my own project.

What I ended up doing was just using the client separately, and setting the token on the client object and hitting the webhook endpoints that way.

Here's a snippet:

$post_data = [
    'endpoint' => //route to the endpoint that I want CU to hit
    'events'   => [
        'taskUpdated',
    ],
    'list_id'  => config('clickup.opportunities.id'),
];

$webhook = $clickup_client->post('team/' . config('clickup.team.id') . '/webhook', $post_data);

Then I wrap all that ^ in a try-catch just in case.

Ceepster14 commented 3 years ago

Hi,

Thanks for that, I'll give it a try. I resorted Postman to handle the webhook setup, but it will be good to bring it back into the project.