OK, here is a plugin that creates custom webhook events:
I developed it against Jiwa 7.2.1.0 SR14 running the REST API plugin v7.2.1.32.
The plugin creates webhook events which fire during inventory item save ONLY if inventory custom field "I'm Special" is true (ticked).
Webhook event names:
"inventory.specialcreated"
"inventory.specialupdated"
"inventory.specialdeleted"
You will see where the webhook is "fired" in the code (line 38):
- 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);
That is where you could change the body variable. Before making the above call you could go read your custom productIDs via the supplied inventoryItem object. Using those productIDs you could instantiate and read in other inventory objects or entities. You could then deserialise those additional inventory objects/entities, and perhaps append some or all of the resultant json to the existing body variable, which in turn gets sent on to the webhook.
Notes:
1. A plugin for custom webhooks must have a class that implements IJiwaRESTAPIPlugin, so that IIS or the Jiwa API service will pick it up and run the contained "Configure()" function. It is in here that you add the webhook definitions, making calls out the the main Rest API plugin methods and properties (the main REST API plugin is added as a reference on the "Plugin References" tab).
2. Set the "Execution Order" of custom webhook plugins to be a number higher than that of the main REST API plugin. This allows the main REST API plugin to set up it's webhook collection ready for when your plugin comes along to add to it.
3. One trap was the passing of the "correct" plugin name when firing the webhook. You should pass the plugin name of the main REST API plugin - this is because in the Webhook() method the plugin name is used to read in the "WebhooksHostURL" system setting. Thankfully said plugin name was available via a static property in the referenced main REST API plugin.
I hope this sets you on your way.