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