Change Behaviour of webhooks

Discussions relating to the REST API of Jiwa 7.

Change Behaviour of webhooks

Postby SBarnes » Sun Jul 05, 2020 3:08 pm

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.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1617
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Change Behaviour of webhooks

Postby Mike.Sheen » Mon Jul 06, 2020 10:56 am

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?
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2440
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 755

Re: Change Behaviour of webhooks

Postby SBarnes » Mon Jul 06, 2020 11:00 am

You mean double hop it against the api itself?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1617
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Change Behaviour of webhooks

Postby Mike.Sheen » Mon Jul 06, 2020 11:04 am

SBarnes wrote:You mean double hop it against the api itself?


Yep
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2440
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 755

Re: Change Behaviour of webhooks

Postby SBarnes » Mon Jul 06, 2020 11:45 am

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.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1617
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Change Behaviour of webhooks

Postby SBarnes » Mon Jul 06, 2020 4:40 pm

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?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1617
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Change Behaviour of webhooks

Postby Mike.Sheen » Mon Jul 06, 2020 5:40 pm

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.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2440
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 755

Re: Change Behaviour of webhooks

Postby SBarnes » Mon Jul 06, 2020 5:52 pm

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
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1617
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Change Behaviour of webhooks

Postby SBarnes » Thu Jul 09, 2020 5:12 pm

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?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1617
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Change Behaviour of webhooks

Postby SBarnes » Mon Feb 01, 2021 4:14 pm

How can you reference WebHookEvents and Webhook from another plugin?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1617
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Next

Return to REST API

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron