Webhooks POST URL  Topic is solved

Discussions relating to the REST API of Jiwa 7.

Webhooks POST URL

Postby minhhieu106 » Mon Apr 16, 2018 6:59 pm

Hi Mike,

Follow the URL: https://docs.jiwa.com.au/display/J7UG/W ... est_csharp

=> Add a subscription for Subscriber with ID b25a2922-931b-4447-9160-3984b91c02f4 - when a sales order is created, perform a POST operation on the URL https://example.com/api/dosomething
Code: Select all
using (var webClient = new System.Net.WebClient())
{
    string json = Newtonsoft.Json.JsonConvert.SerializeObject(new
        {
            SubscriberID = "2a84b900-d178-4de4-8d11-18b318c0276b",
            URL = "https://example.com/api/dosomething",
            EventName = "salesorder.created"
        });
    responsebody = webClient.UploadString("https://api.jiwa.com.au/Webhooks/Subscribers/b25a2922-931b-4447-9160-3984b91c02f4/Subscriptions/", "POST", json);
}


I try to create a api to receive the posting data from webhooks. But it is failed (Bad Request error). Below is the sending code on API Webhooks plugin.

Code: Select all
   try
               {            
                  // This is the actual POST to the webhook
                  subscription.URL.PostStringToUrl(queueItem.Body,
                                           requestFilter: webRequest =>
                                           {
                                             foreach(SY_WebhookSubscriptionRequestHeader subscriptionRequestHeader in subscriptionRequestHeaders)
                                             {
                                                webRequest.Headers[subscriptionRequestHeader.Name] = subscriptionRequestHeader.Value;
                                             }
                                           });
                  queueResponse.HTTPCode = 200;
                  newStatus = 1;                                                   
               }
               catch (System.Exception ex)
               {            
                  while (ex.InnerException != null) ex = ex.InnerException;
                  
                  newStatus = 2;
                  queueResponse.Message = ex.Message;
                  int statusCode = 0;
                  
                  if (ex.GetStatus() != null)
                     statusCode = (int)ex.GetStatus();
                  
                  queueResponse.HTTPCode = statusCode;
                  
                  if ((statusCode >= 200 && statusCode < 300) || ex.IsAny300() || statusCode == 410)
                     newStatus = 3;   // Permanent fail - we do not attempt to retry these                     
               }


Do you have any sample codes for the api to receive the posting data from webhooks (e.g. code for wcf or asmx).

Thank you
minhhieu106
Occasional Contributor
Occasional Contributor
 
Posts: 49
Joined: Thu Mar 29, 2018 3:29 pm
Topics Solved: 0

Re: Webhooks POST URL  Topic is solved

Postby Mike.Sheen » Wed Apr 18, 2018 11:41 am

Hi minhhieu106,

I don't have an example handy, but I tested the webhooks by using Zapier to receive the POST operation to send a tweet. Zapier has a free tier which should work fine for your testing purposes.

Mike
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: 2445
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 757

Re: Webhooks POST URL

Postby minhhieu106 » Thu Apr 19, 2018 1:25 am

Hi Mike,

I got it now.

Thank you
minhhieu106
Occasional Contributor
Occasional Contributor
 
Posts: 49
Joined: Thu Mar 29, 2018 3:29 pm
Topics Solved: 0


Return to REST API

Who is online

Users browsing this forum: No registered users and 1 guest