How to use pre defined Jiwa webhooks  Topic is solved

Discussions relating to the REST API of Jiwa 7.

Re: How to use pre defined Jiwa webhooks  Topic is solved

Postby Mike.Sheen » Mon Jul 25, 2022 1:52 pm

Hi Sameer,

Here is a simple sample plugin which will add a field to the json for webhooks sent out for debtors created or updated.

The entire plugin code is shown below. The plugin needs to have a Plugin Reference to the REST API plugin, which the attached does.

Code: Select all
using System;
using System.Diagnostics;
using ServiceStack;
using ServiceStack.Model;
using ServiceStack.Web;

public class CustomiseWebhook : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaRESTAPIPlugin
{
   public void Configure(JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin, ServiceStack.ServiceStackHost AppHost, Funq.Container Container, JiwaFinancials.Jiwa.JiwaApplication.Manager JiwaApplicationManager)
    {
      AppHost.RegisterTypedRequestFilter<JiwaFinancials.Jiwa.JiwaServiceModel.WebhooksEventsPOSTRequest>((req, res, dto) => { WebhooksEventsPOSTRequestFilter(req, res, dto); });
   }
   
   public void WebhooksEventsPOSTRequestFilter(IRequest req, IResponse res, JiwaFinancials.Jiwa.JiwaServiceModel.WebhooksEventsPOSTRequest dto)
    {
      if (dto.EventName == "debtor.created" || dto.EventName == "debtor.updated")
      {
         // dto.Body is the JSON for the debtor.  We can modify that, and that is what is used for the webhook.
         // We're going to modify it by deserialising it into our own object which inherits from the debtor DTO object, and
         // then set our custom field, and then serialise that back to a string.
         ExtendedDebtor customDebtorDTO = dto.Body.FromJson<ExtendedDebtor>();
         customDebtorDTO.MyCustomField = "This is a Test";
         dto.Body = customDebtorDTO.ToJson<ExtendedDebtor>();
      }      
   }
}

public class ExtendedDebtor : JiwaFinancials.Jiwa.JiwaServiceModel.Debtors.Debtor
{
   virtual public string MyCustomField { get; set; }
}
Attachments
Plugin Customise Webhook Payload.xml
(10.09 KiB) Downloaded 98 times
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: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: How to use pre defined Jiwa webhooks

Postby NatashaDevon » Mon Jul 25, 2022 5:00 pm

please share an example to get the event on inventory or debtor created.
NatashaDevon
I'm new here
I'm new here
 
Posts: 7
Joined: Sun Jul 24, 2022 2:53 am

Re: How to use pre defined Jiwa webhooks

Postby Mike.Sheen » Mon Jul 25, 2022 5:03 pm

NatashaDevon wrote:please share an example to get the event on inventory or debtor created.


My previous post shows debtor created or debtor updated. Is that not sufficient?
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: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: How to use pre defined Jiwa webhooks

Postby NatashaDevon » Mon Jul 25, 2022 5:11 pm

As SBarnes replied that we can not customize the existing webhooks object. Like adding some extra fields before sending to the third-party application. So now I am asking that can I get the debtor/inventory related events inside Jiwa?



If it possible then its make my life easier I will handle it manually using API
NatashaDevon
I'm new here
I'm new here
 
Posts: 7
Joined: Sun Jul 24, 2022 2:53 am

Re: How to use pre defined Jiwa webhooks

Postby Mike.Sheen » Mon Jul 25, 2022 5:23 pm

NatashaDevon wrote:we can not customize the existing webhooks object


My previous example customises the JSON being sent by webhooks for the debtor.created and debtor.updated events, this is what I thought you asked for.

NatashaDevon wrote:So now I am asking that can I get the debtor/inventory related events inside Jiwa?


Yes. I created a sample plugin for you - attached. Note this is purely business logic events, and not related to the REST API.
Attachments
Plugin SameerTest.xml
(12.29 KiB) Downloaded 88 times
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: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Previous

Return to REST API

Who is online

Users browsing this forum: No registered users and 1 guest