Page 1 of 1

Webhooks POST URL

PostPosted: Mon Apr 16, 2018 6:59 pm
by minhhieu106
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

Re: Webhooks POST URL  Topic is solved

PostPosted: Wed Apr 18, 2018 11:41 am
by Mike.Sheen
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

Re: Webhooks POST URL

PostPosted: Thu Apr 19, 2018 1:25 am
by minhhieu106
Hi Mike,

I got it now.

Thank you