Skip to content

Commit eb7ee99

Browse files
author
Thomas Gilbert
committed
add new page and section
1 parent 20bf66d commit eb7ee99

File tree

2 files changed

+176
-1
lines changed

2 files changed

+176
-1
lines changed

src/_data/sidenav/partners.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ sections:
88
title: Conceptual model
99
- path: /partners/sources
1010
title: Build a Source
11-
- section_title: Build a Destination
11+
- path: /partners/direct-destination
12+
title: Build a Direct Destination
13+
- section_title: Build an Actions Destination
1214
slug: partners/subscriptions
1315
section:
1416
- path: /partners/destinations

src/partners/direct-destination.md

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
---
2+
title: Building a Direct Destination
3+
redirect_from: '/partners/build-webhook/'
4+
---
5+
6+
Direct Destinations allow Segment Partners to ingest Segment Event Data using a just webhook. This guide explains how to set up your webhook with Segment.
7+
8+
## Getting Started
9+
10+
Review the steps outlined in the [Developer Center Overview](/docs/partners). This document outlines specific details for Step four as it relates to building a Subscription Webhook.
11+
12+
1. Apply to become a [Segment Select Partner](https://segment.com/partners/integration/){:target="_blank"}.
13+
2. Understand Segment's [Conceptual Model](/docs/partners/conceptual-model) and [Spec](/docs/connections/spec).
14+
3. [Request access to the Segment Developer Portal](https://segment.com/partners/developer-portal){:target="_blank"}.
15+
4. Once approved, select "Build a direct destination" within the [Developer Portal](https://app.segment.com/dev-portal/overview){:target="_blank"}.
16+
5. Build and test your Component(s).
17+
6. Add your catalog metadata.
18+
6. Publish documentation.
19+
7. Submit your Destination for review.
20+
8. Launch into _Public Beta_!
21+
22+
## Build
23+
24+
Begin by selecting "Build a direct destination" within the [Developer Portal](https://app.segment.com/dev-portal/overview). Next, you will see a field to input your destination name and slug (Once created you will not be able to change the destination slug). Within the "Build and test" section of the portal UI, add the destination endpoint where Segment data will be forwarded to.
25+
26+
Continue reading below to understand what is expected when accepting and responding to Segment data.
27+
28+
### Accepting Segment Data
29+
30+
To receive data from Segment, you must provide a server with a static endpoint that can accept HTTPS requests.
31+
32+
The endpoint must:
33+
- *Accept POST requests.* Segment sends customer data to the endpoint you designate in POST requests.
34+
- *Accept JSON data.* Segment sends data in JSON.
35+
- *Use HTTPS.* Segment transmits potentially sensitive data on behalf of customers, and HTTPS is the first step in making sure their data stays safe.
36+
37+
#### Authorization
38+
39+
Segment sends your user's API key with requests, and you can use it to authenticate requests. This is the API key _you_ give to your users; it is not a Segment API key.
40+
41+
Segment sends the key in the `Authorization` header using the `Basic` authentication type. It is Base64 encoded with your user's API key as the username, and an empty password.
42+
43+
For example, if your user's API key was `segment`, Segment would Base64 encode the string `'segment:'` and prepend the string `'Basic '`. The colon is always present, even when the password is absent.
44+
45+
This would result in a final string of `'Basic c2VnbWVudDo='`. This is what is contained in the `Authorization` header. Like any Authorization header, you must decode the string when you receive it.
46+
47+
See the [headers](#headers) section for more details.
48+
49+
#### Custom Settings
50+
All direct destinations have an API key setting by default, which Segment will send in the Authorization Header. To add more custom settings, go to the `Settings Editor` page. Any custom settings you add will be sent in the custom header `X-Segment-Settings` (See the [headers](#headers) section for more details.)
51+
52+
53+
#### Headers
54+
55+
Segment sends you the following HTTP headers with all requests:
56+
57+
| Header | Description | Example |
58+
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
59+
| `Accept` | Segment accepts any content type, but ignores responses unless this header is set to `application/json`. | `Accept: */*` |
60+
| `Authorization` | Segment sends your user's API token in this header, with the `Basic` authentication type. | `Authorization: Basic c2VnbWVudDo=` |
61+
| `Cache-Control` | Each request Segment sends is a new event. Segment does not expect your application to cache. | `Cache-Control: no-cache` |
62+
| `Connection` | Segment uses HTTP/1.1's keep-alive functionality whenever possible, however this is optional. | `Connection: Keep-Alive` |
63+
| `Content-Length` | Segment always sends you the length of the request in bytes. | `Content-Length: 348` |
64+
| `Content-Type` | Segment indicates the type of data it sent you (this will always be JSON), along with Segment's vendor type. | `Content-Type: application/json` |
65+
| `User-Agent` | Segment sends you this field every time. | `User-Agent: Segment.io/1.0` |
66+
| `X-Segment-Settings` | Except for the API key (which is sent in the Authorization header), Segment will send the base 64 encoding of the rest of your custom settings encoded in this header. | `X-Segment-Settings: eyJjdXN0b21TZXR0aW5nT25lIjoiY3VzdG9tIHNldHRpbmcgdmFsdWUifQ==` |
67+
68+
69+
#### Request Body
70+
71+
Segment's [Spec](/docs/connections/spec) standardizes the data that you can expect from Segment. You can choose to implement four types types of calls:
72+
73+
- Who is this? `.identify(userId, traits)`
74+
- What are they doing? `.track(userId, event, properties)`
75+
- Where are they doing it? `.page(userId, pageName, properties)`
76+
- What group are they part of? `.group(userId, groupId, groupTraits)`
77+
78+
For example, you might implement the `.identify(userId, traits)` call to create contacts in an email marketing application. You can expect the following customer information as a JSON object in the call body:
79+
80+
```json
81+
{
82+
"anonymousId": "1234",
83+
"context": {
84+
"ip": "8.8.8.8",
85+
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36"
86+
},
87+
"messageId": "022bb90c-bbac-11e4-8dfc-aa07a5b093db",
88+
"receivedAt": "2015-02-23T22:28:55.387Z",
89+
"sentAt": "2015-02-23T22:28:55.111Z",
90+
"traits": {
91+
"name": "John Doe",
92+
"email": "[email protected]",
93+
"plan": "premium",
94+
"logins": 5
95+
},
96+
"type": "identify",
97+
"userId": "5678",
98+
"version": "1.1"
99+
}
100+
```
101+
102+
> info ""
103+
> The casing on these fields will vary by customer, so be ready to accept any casing.
104+
105+
106+
#### Status Code
107+
108+
Segment uses standard HTTP status code conventions to help diagnose problems quickly and give better insight into how the destination is working.
109+
110+
Upon receiving data, your endpoint should reply with one of the following status codes:
111+
112+
| Code | Reason |
113+
| ----- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
114+
| `200` | You've accepted and successfully processed the message. |
115+
| `202` | You've accepted the message, but have not yet processed it. |
116+
| `400` | The message is malformed, or otherwise contains an error that is the client's fault. |
117+
| `401` | The client's API key is malformed, has expired, or is otherwise no longer valid. |
118+
| `403` | The client's API key is valid, but has been rejected due to inadequate permissions. |
119+
| `500` | If you encounter an internal error when processing the message, reply with this code. (Hopefully you won't have to send too many of these.) |
120+
| `501` | If Segment sends you an [API call type](https://segment.com/docs/connections/spec/#api-calls) (indicated by the `type` property included on all messages) you don't support, reply with this code. Read more about the API call types Segment supports [here](https://segment.com/docs/connections/spec/#api-calls). |
121+
| `503` | Send Segment this code when your endpoint is temporarily down for maintenance or otherwise not accepting messages. This helps Segment avoid dropping users' messages during your downtime. |
122+
123+
#### Response Body
124+
125+
You can normally send back an empty body, but when sending back a `4xx`- or `5xx`-class error, you can optionally send Segment a diagnostic message that explains the error. This message is displayed to the user in the Segment debugger, and is be used in Segment's Event Delivery summaries.
126+
127+
Be sure to send JSON (and set your `Content-Type` header to `application/json`), and send your message in the `message` property.
128+
129+
Here's an example of a `401` response that helps a user track down why their calls aren't appearing in your tool's UI:
130+
131+
```json
132+
{
133+
"message": "API token expired"
134+
}
135+
```
136+
137+
Or, if your tool requires an email address in order to accept calls, use this example `400` reply:
138+
139+
```json
140+
{
141+
"message": "Missing email address"
142+
}
143+
```
144+
145+
## Test
146+
147+
When testing your integration, proceed through two separate flows:
148+
1. Test that your endpoint successfully ingests data in the way you would expect.
149+
2. Mimic a user implementing your integration within their Segment workspace.
150+
151+
### Your Endpoint
152+
153+
Test your code directly from the Developer Portal UI. Use the `Send Test Events` tab and review the test events to make sure your destination works as expected.
154+
155+
156+
In the debugger panel, check the two outputs. The **Request from Segment** and the **Response from destination**.
157+
158+
* **Request from Segment** - What we posted to your endpoint
159+
* **Response from destination** - How your server responded
160+
161+
### The User Flow
162+
163+
The ultimate goal is for Partners like yourself to create and publish high quality Destinations in [the Segment Catalog](https://segment.com/catalog/). Your Segment account doubles as a sandbox account to test your destination while you are still in a private "building" state.
164+
165+
To test your Destination in the Catalog, click the "View in workspace" button in the "Test in your workspace" section. This redirects to you a URL like https://app.segment.com/WORKSPACE-SLUG/destinations/catalog/APP-SLUG, which is your catalog entry.
166+
167+
From here, click "Configure App", select a Source, and click "Confirm Source". You can now configure your destination by setting the "API Key", then clicking the toggle to enable the destination.
168+
169+
Next you can click the "Event Tester" tab to send data to your destination. Here you can see what requests Segment sends to your destination and introspect the response you are returning. Learn more about the event tester [here](/docs/guides/best-practices/how-do-I-test-my-connections/).
170+
171+
Now you can use the JavaScript SDK in a browser to generate real analytics events.
172+
173+
Finally you should verify the data in your service.

0 commit comments

Comments
 (0)