Skip to main content
Integrating with Segment
Updated over a week ago

This document describes how to integrate with the Segment API via webhook integration.



Configure HTTP API Source in Segment

First, we need to configure an HTTP API source in Segment:

  • Go to "Connections->Sources" and click "Add Source"

Document image
  • Choose "HTTP API Server"

Document image
  • Name it and click "Add Source"

  • Copy the "Write Key"

Document image
  • Create the Authorization header:

    The Authorization header structure is: Authorization: Basic <encoded key>.

    While <encoded key> is generated by taking the Write Key from the Segment Source, appending a colon (:) to the end and encoding everything to Base64.

    For example, assuming our Write Key is abc123, we'll encode abc123: to Base64 and get YWJjMTIzOg== so the Authorization header becomes Authorization: Basic YWJjMTIzOg==

Send an Event To Segment

Identify Event

To send an event to Segment You'll need an access token (follow the instructions above if you don't have a token)

Configure Automation

  1. Go to Automations

  2. Add New Automation

    1. Add the automation name

    2. Define the trigger

      1. Choose pattern or journey

    3. Define the action

      1. In the "Action Settings" choose "HTTP Request"

      2. In the "Automation URL" insert https://api.segment.io/v1/identify

      3. In the "JSON Payload" insert a valid "identify event", for example,

        { 
        "userId": "{{userId}}",
        "traits": {
        "email": "{{userEmail}} ",
        "name": "{{userName}}"
        },
        "timestamp": "{{clientTimestampEndTime}}"
        }

        for more information about the Identify spec follow this link https://segment.com/docs/connections/sources/catalog/libraries/server/http-api/#identify

      4. In the "Headers" insert

        { 
        "Accept": "Application/json",
        "Content-type": "Application/json",
        "Authorization": "Basic <the access token>"
        }
Document image

Group Event

To send an event to Segment You'll need an access token (follow the instructions above if you don't have a token)

Configure Automation

  1. Go to Automations

  2. Add New Automation

    1. Add the automation name

    2. Define the trigger

      1. Choose pattern or journey

    3. Define the action

      1. In the "Action Settings" choose "HTTP Request"

      2. In the "Automation URL" insert https://api.segment.io/v1/group

      3. In the "JSON Payload" insert a valid "identify event", for example,

        { 
        "userId": "{{userId}}",
        "groupId": "{{accountId}}",
        "traits": {
        "name": "{{accountName}}"
        },
        "timestamp": "{{clientTimestampEndTime}}"
        }

        for more information about the Identify spec follow this link https://segment.com/docs/connections/sources/catalog/libraries/server/http-api/#group

      4. In the "Headers" insert

         { 
        "Accept": "Application/json",
        "Content-type": "Application/json",
        "Authorization": "Basic <the access token>"
        }
Document image

Track Event

To send an event to Segment You'll need an access token (follow the instructions above if you don't have a token)

Configure Automation

  1. Go to Automations

  2. Add New Automation

    1. Add the automation name

    2. Define the trigger

      1. Choose pattern or journey

    3. Define the action

      1. In the "Action Settings" choose "HTTP Request"

      2. In the "Automation URL" insert https://api.segment.io/v1/track

      3. In the "JSON Payload" insert a valid "identify event", for example,

        { 
        "userId": "{{userId}}",
        "event": "{{usagePatternName}}",
        "properties": {
        "duration": "{{duration}}"
        },
        "timestamp": "{{clientTimestampEndTime}}"
        }

        for more information about the Identify spec follow this link https://segment.com/docs/connections/sources/catalog/libraries/server/http-api/#track

      4. In the "Headers" insert

        {     
        "Accept": "Application/json",
        "Content-type": "Application/json",
        "Authorization": "Basic <the access token>"
        }
Document image

Did this answer your question?