@zenginehq/frontend-webhooks
v1.2.0
Published
Helper library for working with webhooks in Zengine frontend plugins.
Downloads
9
Readme
Frontend Webhooks
Helper module for working with webhooks in Zengine frontend plugins.
Installation
# Run this from your frontend plugin's src diretory.
npm i @zenginehq/frontend-webhooks --save
It's important that this gets inside under the plugins/myplugin/src
directory, alongside your plugin's other code if not Maya won't build it properly.
Usage
plugin.controller('MyAwesomeController', ['$scope', 'wgnWebhook', 'wgnScheduledWebhook', function ($scope, webhook, scheduledWebhook) {
$scope.onSomething(function () {
var params = {
//'url': 'http://www.example.com/endpoint',
'url': 'myservice', // <--- notice how you can pass a backend service name and the url will get built automatically.
'form.id': 123
};
webhook.create(params).then(function (webhook) {
console.log(webhook.id);
console.log(webhook.secretKey);
});
// Enable or disable webhooks.
webhook.enable(webhookId);
webhook.disable(webhookId);
// Use the exact same API to deal with Scheduled Webhooks.
scheduledWebhook.create();
scheduledWebhook.enable();
scheduledWebhook.disable();
});
}]);
Regular vs Scheduled Webhooks
Notice in the example above there are 2 different services being used wgnWebhook
and wgnScheduledWebhook
, they each deal with different kinds of Zengine resources but both expose the exact same API with the following methods available:
- create: creates a new webhook
- enable: enables a webhook
- disable: disables a webhook
- delete: deletes a webhook
- update: updates a webhook