sameermoin wrote:Its a general header but in my case, I want to add a InventoryId in a header and it would be different for all requests. Do I need to add headers in a body parameter of the Webhook method ?
Ok - I missed that part of your original post.
Note that this:
- Code: Select all
JiwaFinancials.Jiwa.RESTAPIPlugin.BusinessLogicPlugin.Webhook(inventoryItem.Manager, body, (inventoryItem.InsertFlag) ? "inventory.specialcreated" : (inventoryItem.DeleteFlag) ? "inventory.specialdeleted" : "inventory.specialupdated", JiwaFinancials.Jiwa.RESTAPIPlugin.BusinessLogicPlugin.PluginName);
Isn't actually sending the webhook to the recipient. It's signaling to the REST API service to send webhooks to any subscriptions there may be for the event. You want to add headers to the POST to all the subscriptions, which occurs in the CallWebhook method of the REST API plugin:
- Code: Select all
try
{
// This is the actual POST to the webhook
subscription.URL.PostStringToUrl(message.Body,
requestFilter: webRequest =>
{
foreach (SY_WebhookSubscriptionRequestHeader subscriptionRequestHeader in subscriptionRequestHeaders)
{
if(subscriptionRequestHeader.Name.ToUpper() == "CONTENT-TYPE")
{
webRequest.ContentType = subscriptionRequestHeader.Value;
}
else
{
webRequest.Headers[subscriptionRequestHeader.Name] = subscriptionRequestHeader.Value;
}
}
});
messageResponse.HTTPCode = 200;
newStatus = 1;
}
catch (System.Exception ex)
{
As you can see there is no opportunity for you to add dynamic headers at this point. I've created improvement
DEV-9720 to add a way of doing what you want.
If you can, things will be cleaner and simpler if you can have your webhook receiver accept this information in the body instead of the header.
If you can't, then you could hack the system by adding a custom route in the API to act as the webhook receiver, and it could add your headers or add an event that a plugin could listen to and add the headers there and THAT would send to the webhook recipients. You'd need to change all your webhook subscriber URL's to be the internal custom webhook receiver route and store in the body the real subscriber URL to route to.
It's possible, but not recommended as things will get messy and confusing.