← Segment

Webhook Destination (Instant) from Segment API

Pipedream makes it easy to connect APIs for Segment and 900+ other apps remarkably fast.

Trigger workflow on
Webhook Destination (Instant) from the Segment API
Next, do this
Connect to 900+ APIs using code and no-code building blocks
No credit card required
Into to Pipedream
Watch us build a workflow
Watch us build a workflow
7 min
Watch now ➜
Trusted by 250,000+ developers from startups to Fortune 500 companies:
Trusted by 250,000+ developers from startups to Fortune 500 companies

Developers Pipedream

Getting Started

Trigger a workflow on Webhook Destination (Instant) with Segment API. When you configure and deploy the workflow, it will run on Pipedream's servers 24x7 for free.

  1. Configure the Webhook Destination (Instant) trigger
    1. Connect your Segment account
    2. Select a Workspace
    3. Select a Source
  2. Add steps to connect to 900+ APIs using code and no-code building blocks
  3. Deploy the workflow
  4. Send a test event to validate your setup
  5. Turn on the trigger

Integrations

Send Message with Discord Webhook API on Webhook Destination (Instant) from Segment API
Segment + Discord Webhook
 
Try it
Add Multiple Rows with Google Sheets API on Webhook Destination (Instant) from Segment API
Segment + Google Sheets
 
Try it
Get Film with SWAPI - Star Wars API on Webhook Destination (Instant) from Segment API
Segment + SWAPI - Star Wars
 
Try it
Create Multiple Records with Airtable API on Webhook Destination (Instant) from Segment API
Segment + Airtable
 
Try it
Send any HTTP Request with HTTP / Webhook API on Webhook Destination (Instant) from Segment API
Segment + HTTP / Webhook
 
Try it

Details

This is a pre-built, open source component from Pipedream's GitHub repo. The component is developed by Pipedream and the community, and verified and maintained by Pipedream.

To contribute an update to an existing component or create a new component, create a PR on GitHub. If you're new to Pipedream component development, you can start with quickstarts for trigger span and action development, and then review the component API reference.

Webhook Destination (Instant) on Segment
Description:Send events to a webhook
Version:0.0.1
Key:segment-webhook-destination

Code

import { v4 as uuid } from "uuid";
import { createHmac } from "crypto";
import constants from "../../common/constants.mjs";
import segmentApp from "../../segment.app.mjs";

export default {
  key: "segment-webhook-destination",
  name: "Webhook Destination (Instant)",
  description: "Send events to a webhook",
  version: "0.0.1",
  type: "source",
  props: {
    segmentApp,
    db: "$.service.db",
    http: {
      type: "$.interface.http",
      customResponse: true,
    },
    workspace: {
      propDefinition: [
        segmentApp,
        "workspace",
      ],
    },
    source: {
      propDefinition: [
        segmentApp,
        "source",
        ({ workspace }) => ({
          workspace,
        }),
      ],
    },
  },
  hooks: {
    async activate() {
      const { source } = this;
      const secret = uuid();
      const destination = this.getDestination();
      const baseName = `${source}/destinations/${destination}`;

      await this.segmentApp.createDestination({
        source: `/${source}`,
        data: {
          destination: {
            name: baseName,
            enabled: true,
            connection_mode: "UNSPECIFIED",
            config: [
              {
                name: `${baseName}/config/sharedSecret`,
                type: "string",
                value: secret,
              },
              {
                name: `${baseName}/config/hooks`,
                type: "mixed",
                value: [
                  {
                    hook: this.http.endpoint,
                  },
                ],
              },
            ],
          },
        },
      });
      this.setSharedSecret(secret);
    },
    async deactivate() {
      return this.segmentApp.deleteDestination({
        source: `/${this.source}`,
        destination: this.getDestination(),
      });
    },
  },
  methods: {
    isValid(signature, bodyRaw) {
      const digest = createHmac("sha1", this.getSharedSecret())
        .update(Buffer.from(bodyRaw, "utf8"))
        .digest("hex");
      return signature === digest;
    },
    getDestination() {
      return "webhooks";
    },
    setSharedSecret(secret) {
      this.db.set(constants.SHARED_SECRET, secret);
    },
    getSharedSecret() {
      return this.db.get(constants.SHARED_SECRET);
    },
  },
  async run(event) {
    const {
      headers,
      body,
      bodyRaw,
    } = event;

    const signature = headers["x-signature"];

    if (this.isValid(signature, bodyRaw)) {

      this.http.respond({
        status: 200,
        headers: {
          "x-signature": signature,
        },
      });

      this.$emit(body, {
        id: signature,
        summary: `Received ${body.type} event`,
        ts: Date.parse(body.timestamp),
      });
    }
  },
};

Configuration

This component may be configured based on the props defined in the component code. Pipedream automatically prompts for input values in the UI and CLI.
LabelPropTypeDescription
SegmentsegmentAppappThis component uses the Segment app.
N/Adb$.service.dbThis component uses $.service.db to maintain state between component invocations.
N/Ahttp$.interface.httpThis component uses $.interface.http to generate a unique URL when the component is first instantiated. Each request to the URL will trigger the run() method of the component.
WorkspaceworkspacestringSelect a value from the drop down menu.
SourcesourcestringSelect a value from the drop down menu.

Authentication

Segment uses API keys for authentication. When you connect your Segment account, Pipedream securely stores the keys so you can easily authenticate to Segment APIs in both code and no-code steps.

Segment's Config API is accessed programmatically using access tokens. Create access tokens via the Access Management page in your account: https://app.segment.com/{your-workspace-name}/settings/access-management. See Authentication for more details.

About Segment

Customer data platform

More Ways to Use Segment

Actions

Associate an identified user with a group with the Segment API

Group lets you associate an identified user with a group (note requires userId or anonymousId). See the docs here

 
Try it
Associate one identity with another with the Segment API

Alias is how you associate one identity with another. See the docs here

 
Try it
Identify a user, tie them to their actions and record traits about them with the Segment API

identify lets you tie a user to their actions and record traits about them. It includes a unique User ID and any optional traits you know about them (note requires userId or anonymousId). See the docs here

 
Try it
Record page views on your website with the Segment API

The page method lets you record page views on your website, along with optional extra information about the page being viewed (note requires userId or anonymousId). See the docs here

 
Try it
Record whenever a user sees a screen with the Segment API

The screen method let you record whenever a user sees a screen of your mobile app (note requires userId or anonymousId). See the docs here

 
Try it