Skip to content

Commit b860967

Browse files
authored
Merge pull request #6147 from segmentio/niall/http_writekey
Add docs on including writeKey in the body to authenticate
2 parents c1ee28e + 7776f02 commit b860967

File tree

1 file changed

+35
-11
lines changed
  • src/connections/sources/catalog/libraries/server/http-api

1 file changed

+35
-11
lines changed

src/connections/sources/catalog/libraries/server/http-api/index.md

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,28 @@ Segment has native [sources](/docs/connections/sources/) for most use cases (lik
1111

1212
### Authentication
1313

14-
Choose between [basic authentication](#basic-authentication) and [OAuth](#oauth) to authenticate requests.
15-
16-
#### Basic authentication
14+
Choose between [writeKey authentication](#writeKey-authentication), [basic authentication](#basic-authentication) and [OAuth](#oauth) to authenticate requests.
1715

16+
#### writeKey authentication
1817
Authenticate to the Tracking API by sending your project's **Write Key** along with a request.
19-
Authentication uses HTTP Basic Auth, which involves a `username:password` that is base64 encoded and prepended with the string `Basic`.
18+
The authentication writeKey should be sent as part of the body of the request. This will be encrypted over https.
19+
20+
```
21+
curl --location 'https://api.segment.io/v1/track' \
22+
--header 'Content-Type: application/json' \
23+
--data-raw '{
24+
"event": "happy-path-a3ef8a6f-0482-4694-bc4d-4afba03a0eab",
25+
"email": "[email protected]",
26+
"userId": "123",
27+
"writeKey": "DmBXIN4JnwqBnTqXccTF0wBnLXNQmFtk"
28+
}'
29+
```
30+
31+
> info ""
32+
> For this auth type, you do not need to set any authentication header.
33+
34+
#### Basic authentication
35+
Basic authentication uses HTTP Basic Auth, which involves a `username:password` that is base64 encoded and prepended with the string `Basic`.
2036

2137
In practice that means taking a Segment source **Write Key**,`'abc123'`, as the username, adding a colon, and then the password field is left empty. After base64 encoding `'abc123:'` becomes `'YWJjMTIzOg=='`; and this is passed in the authorization header like so: `'Authorization: Basic YWJjMTIzOg=='`.
2238

@@ -105,7 +121,8 @@ POST https://api.segment.io/v1/identify
105121
"context": {
106122
"ip": "24.5.68.47"
107123
},
108-
"timestamp": "2012-12-02T00:30:08.276Z"
124+
"timestamp": "2012-12-02T00:30:08.276Z",
125+
"writeKey": "YOUR_WRITE_KEY"
109126
}
110127
```
111128
This call is identifying the user by their unique User ID (the one you know them by in your database) and labeling them with `email`, `name`, and `industry` traits.
@@ -145,7 +162,8 @@ POST https://api.segment.io/v1/track
145162
"context": {
146163
"ip": "24.5.68.47"
147164
},
148-
"timestamp": "2012-12-02T00:30:12.984Z"
165+
"timestamp": "2012-12-02T00:30:12.984Z",
166+
"writeKey": "YOUR_WRITE_KEY"
149167
}
150168
```
151169

@@ -178,7 +196,8 @@ POST https://api.segment.io/v1/page
178196
{
179197
"userId": "019mr8mf4r",
180198
"name": "Tracking HTTP API",
181-
"timestamp": "2012-12-02T00:31:29.738Z"
199+
"timestamp": "2012-12-02T00:31:29.738Z",
200+
"writeKey": "YOUR_WRITE_KEY"
182201
}
183202
```
184203
The `page` call has the following fields:
@@ -210,7 +229,8 @@ POST https://api.segment.io/v1/screen
210229
{
211230
"userId": "019mr8mf4r",
212231
"name": "Tracking HTTP API",
213-
"timestamp": "2012-12-02T00:31:29.738Z"
232+
"timestamp": "2012-12-02T00:31:29.738Z",
233+
"writeKey": "YOUR_WRITE_KEY"
214234
}
215235
```
216236

@@ -249,7 +269,8 @@ POST https://api.segment.io/v1/group
249269
"industry": "Technology",
250270
"employees": 420
251271
},
252-
"timestamp": "2012-12-02T00:31:38.208Z"
272+
"timestamp": "2012-12-02T00:31:38.208Z",
273+
"writeKey": "YOUR_WRITE_KEY"
253274
}
254275
```
255276
The `group` call has the following fields:
@@ -282,7 +303,8 @@ POST https://api.segment.io/v1/alias
282303
{
283304
"previousId": "39239-239239-239239-23923",
284305
"userId": "019mr8mf4r",
285-
"timestamp": "2012-12-02T00:31:29.738Z"
306+
"timestamp": "2012-12-02T00:31:29.738Z",
307+
"writeKey": "YOUR_WRITE_KEY"
286308
}
287309
```
288310
The `alias` call has the following fields:
@@ -365,6 +387,7 @@ POST https://api.segment.io/v1/batch
365387
"timestamp": "2015-2-02T00:30:12.984Z"
366388
}
367389
],
390+
"writeKey": "YOUR_WRITE_KEY",
368391
"context": {
369392
"device": {
370393
"type": "phone",
@@ -422,7 +445,8 @@ POST https://api.segment.io/v1/identify
422445
"Mixpanel": true,
423446
"Kissmetrics": true,
424447
"Google Analytics": false
425-
}
448+
},
449+
"writeKey": "YOUR_WRITE_KEY"
426450
}
427451
```
428452

0 commit comments

Comments
 (0)