Page 1 of 2

Change Behaviour of webhooks

PostPosted: Sun Jul 05, 2020 3:08 pm
by SBarnes
Is there any way to change the default behaviour of webhooks, by this I mean there are case where the concept of webhooks as they stand could be utilised but instead of the default post other behaviour, for example certain web store or third party platforms may require different security to logon or require that you use their SDK/api to send/submit data.

The only other way that I could see doing this would be the whole thing from scratch.

If there was a way to let a delegated event take over the processing of the hook this might be possible.

Re: Change Behaviour of webhooks

PostPosted: Mon Jul 06, 2020 10:56 am
by Mike.Sheen
SBarnes wrote:instead of the default post other behaviour, for example certain web store or third party platforms may require different security to logon or require that you use their SDK/api to send/submit data.


Why not simply create a custom plugin which adds a route to receive the webhook and your subscriptions POST to that, and in there you can do whatever you like?

Re: Change Behaviour of webhooks

PostPosted: Mon Jul 06, 2020 11:00 am
by SBarnes
You mean double hop it against the api itself?

Re: Change Behaviour of webhooks

PostPosted: Mon Jul 06, 2020 11:04 am
by Mike.Sheen
SBarnes wrote:You mean double hop it against the api itself?


Yep

Re: Change Behaviour of webhooks

PostPosted: Mon Jul 06, 2020 11:45 am
by SBarnes
Unconventional but smart this could also apply if you wanted to make a webhook conditional on properties of the payload such as the product category or the state in which a debtor resided or even if you then wanted to update something to Jiwa itself or log something.

Re: Change Behaviour of webhooks

PostPosted: Mon Jul 06, 2020 4:40 pm
by SBarnes
Following the conventions used in the Rest API is it possible to add hooks for other events through another plugin such as capturing the addition of payments through the cashbook, if possible in broad terms what are the steps required?

Re: Change Behaviour of webhooks

PostPosted: Mon Jul 06, 2020 5:40 pm
by Mike.Sheen
SBarnes wrote:Following the conventions used in the Rest API is it possible to add hooks for other events through another plugin such as capturing the addition of payments through the cashbook, if possible in broad terms what are the steps required?


I believe so - Add a handler for the business logic event (SaveEnd is the current convention) and a reference to the REST API plugin.

In your setup, add your new event(s) to the WebHookEvents static property of the REST API:

Code: Select all
WebHookEvents .Add(new JiwaFinancials.Jiwa.JiwaServiceModel.WebHookEvent { Name = "cashbook.created", Description = "Occurs when a new cashbook batch is created" });
WebHookEvents .Add(new JiwaFinancials.Jiwa.JiwaServiceModel.WebHookEvent{ Name = "cashbook.updated", Description = "Occurs when a cashbook batch is modified" });

Then, inside your handler for the cashbook SaveEnd, invoke the static method WebHook:

Code: Select all
Webhook(warehouseTransfer.Manager, body, (cashbook.InsertFlag) ? "cashbook.created" : "cashbook.updated");


That should be it.

Re: Change Behaviour of webhooks

PostPosted: Mon Jul 06, 2020 5:52 pm
by SBarnes
Thanks Mike

I am assuming warehouseTransfer.Manager means cashbook.Manager but I get the idea and given that the Cashbook doesn't DTO I can probably get around it either using its XML serialize and deserilize or try the ServiceStack extension methods in ServiceStack.Text

Thanks again

Re: Change Behaviour of webhooks

PostPosted: Thu Jul 09, 2020 5:12 pm
by SBarnes
I am assuming to go after say debtor specific pricing on inventory follow the event naming convention of inventory.debtorprices.inserted (BusinessObject.Property.Action) etc would avoid the possibility of clashes and make sense?

Re: Change Behaviour of webhooks

PostPosted: Mon Feb 01, 2021 4:14 pm
by SBarnes
How can you reference WebHookEvents and Webhook from another plugin?