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"
Choose "HTTP API Server"
Name it and click "Add Source"
Copy the "Write Key"
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 becomesAuthorization: Basic YWJjMTIzOg==
Follow the link for more information: https://segment.com/docs/connections/sources/catalog/libraries/server/http-api/#authentication
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
Go to Automations
Add New Automation
Add the automation name
Define the trigger
Choose pattern or journey
Define the action
In the "Action Settings" choose "HTTP Request"
In the "Automation URL" insert
https://api.segment.io/v1/identify
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
In the "Headers" insert
{
"Accept": "Application/json",
"Content-type": "Application/json",
"Authorization": "Basic <the access token>"
}
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
Go to Automations
Add New Automation
Add the automation name
Define the trigger
Choose pattern or journey
Define the action
In the "Action Settings" choose "HTTP Request"
In the "Automation URL" insert
https://api.segment.io/v1/group
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
In the "Headers" insert
{
"Accept": "Application/json",
"Content-type": "Application/json",
"Authorization": "Basic <the access token>"
}
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
Go to Automations
Add New Automation
Add the automation name
Define the trigger
Choose pattern or journey
Define the action
In the "Action Settings" choose "HTTP Request"
In the "Automation URL" insert
https://api.segment.io/v1/track
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
In the "Headers" insert
{
"Accept": "Application/json",
"Content-type": "Application/json",
"Authorization": "Basic <the access token>"
}