pipedrive / client-nodejs

Pipedrive API client for NodeJS
MIT License
207 stars 81 forks source link

Adding webhook #517

Closed jeffreyflynt closed 9 months ago

jeffreyflynt commented 9 months ago

When following the example to add a webhook, I get the following error: Missing the required parameter 'subscription_url' when calling addWebhook. Is the below code, the correct way to add a webhook using this library?

let apiInstance = new Pipedrive.WebhooksApi(apiClient);
let opts = Pipedrive.AddWebhookRequest.constructFromObject({
  subscriptionUrl: `https://api.example.com/webhook`,
  eventAction: "updated",
  eventObject: "deal",
  version: "2.0",
});
apiInstance.addWebhook(opts)

Using Pipedrive 22.5.0.

youssef-saber-3 commented 9 months ago

Hey @jeffreyflynt , the parameters for the function should be snake_case like the following

let opts = pipedrive.AddWebhookRequest.constructFromObject({
    subscription_url: `https://api.example.com/webhook`,
    event_action: "create",
    event_object: "deal",
    version: "2.0",
});

and note that you can't use version 2.0 with "event_action" : "updated", you can find more about the v2 webhooks here https://pipedrive.readme.io/docs/guide-for-webhooks-v2

jeffreyflynt commented 9 months ago

@youssef-saber-3 Thanks for that!

To clarify, when I see the properties on the docs page: https://github.com/pipedrive/client-nodejs/blob/master/docs/AddWebhookRequest.md I should always use snake case in my code?

youssef-saber-3 commented 9 months ago

Hey, Yeah, i can see how that can be confusing. we'll work on improving that. i typically refer to the API docs to find the parameter names and descriptions https://developers.pipedrive.com/docs/api/v1/Webhooks#addWebhook

I can also suggest to try out the TypeScript SDK version that we're testing out. it should prevent issues like this where it will provide strong typing for function parameters. this release is still in alpha stage and we'd apreciate any feedback you have if you decide t to give it a try https://www.npmjs.com/package/pipedrive/v/22.3.1-rc.4