This plugin is free for personal and commercial use. Just follow the instructions below.
- Send GET or POST requests
- Configure for specific Vendure events
- Define your own POST body data
Trigger builds or notifications with the customizable webhook plugin for Vendure
yarn install vendure-plugin-webhook
yarn add vendure-plugin-webhook
WebhookPlugin
to your plugins in your vendure-configt.ts
:import { WebhookPlugin } from 'vendure-plugin-webhook';
plugins: [
WebhookPlugin.init({
httpMethod: 'POST',
/**
* Optional: 'delay' waits and deduplicates events for 3000ms.
* If 4 events were fired for the same channel within 3 seconds,
* only 1 webhook call will be sent
*/
delay: 3000,
events: [ProductEvent, ProductVariantEvent],
/**
* Optional: 'requestFn' allows you to send custom headers
* and a custom body with your webhook call.
* By default, the webhook POST will have an empty body
*/
requestFn: async (
event: ProductEvent | ProductVariantEvent,
injector: Injector
) => {
// Get data via injector and build your request headers and body
const { id } = await injector
.get(ChannelService)
.getChannelFromToken(event.ctx.channel.token);
return {
headers: { test: '1234' },
body: JSON.stringify({ createdAt: event.createdAt, channelId: id }),
};
},
}),
];
WebhookPerChannelEntity
to your database. Don't forget to run a migration
OR synchronize: true
if you like living on the edge.Webhook.ui
to your admin UI extensions:import { WebhookPlugin } from 'vendure-plugin-webhook';
plugins: [
AdminUiPlugin.init({
port: 3002,
route: 'admin',
app: compileUiExtensions({
outputPath: path.join(__dirname, '__admin-ui'),
extensions: [WebhookPlugin.ui],
}),
}),
];
For more information on admin UI extensions see https://www.vendure.io/docs/plugins/extending-the-admin-ui/#compiling-as-a-deployment-step
SetWebhook
to administrators who should be able to configure webhooks.settings > webhook
to set the webhook url for the current channel.