Vendure Webhook plugin

Trigger builds or notifications with the customizable webhook plugin for Vendure

Made by a Vendure Silver Partner!
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

D84399c8 38b5 46b3 Be95 375fc23794b5

Installation

yarn install vendure-plugin-webhook
  1. yarn add vendure-plugin-webhook
  2. Add the 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 }),
      };
    },
  }),
];
  1. The plugin adds an entity WebhookPerChannelEntity to your database. Don't forget to run a migration OR synchronize: true if you like living on the edge.
  2. Add 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

  1. Start the server and assign the permission SetWebhook to administrators who should be able to configure webhooks.
  2. Go to settings > webhook to set the webhook url for the current channel.