Skip to content

Send your first event

In your workspace, create a project and choose an environment. Add an event key such as lesson.completed, configure its score, and release the configuration to that environment. Event keys belong to your product: the example key is not a built-in preset.

Create a server OAuth M2M client bound to that project and environment with the events:write scope. Keep its secret on your backend.

Set STREAKLINE_CLIENT_ID and STREAKLINE_CLIENT_SECRET in your local server environment, then exchange them:

Terminal window
curl --fail-with-body https://api.qa.streakline.dev/api/auth/oauth2/token \
--user "$STREAKLINE_CLIENT_ID:$STREAKLINE_CLIENT_SECRET" \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'resource=https://api.qa.streakline.dev' \
--data-urlencode 'scope=events:write'

Use the returned access_token as STREAKLINE_ACCESS_TOKEN. The token’s resource must match the API host. See authentication for renewal and additional scopes.

Use your application’s stable internal user UUID and a unique ID for this occurrence:

Terminal window
curl --fail-with-body https://api.qa.streakline.dev/api/v1/events \
-H "Authorization: Bearer $STREAKLINE_ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
--data '{
"user_id": "550e8400-e29b-41d4-a716-446655440000",
"event_type": "lesson.completed",
"idempotency_key": "lesson:lesson-42:completion-1"
}'

A successful response includes accepted, event_id, score_added, total_score, current_level, and streak information. The score depends on the active configuration.

The SDK is not yet published to the public npm registry. The following example is for integrations with access to the @streakline/sdk package. Use the REST quickstart above to integrate without it.

import { StreaklineServer } from "@streakline/sdk/server";
const streakline = new StreaklineServer({
baseUrl: "https://api.qa.streakline.dev",
auth: process.env.STREAKLINE_ACCESS_TOKEN!,
});
const result = await streakline.track(
"550e8400-e29b-41d4-a716-446655440000",
"lesson.completed",
{ idempotencyKey: "lesson:lesson-42:completion-1" },
);
console.log(result.total_score, result.current_level);

Add profiles:read to a server client to retrieve profiles. For browser or mobile tracking, create a separate credential-issuing client and follow user-bound authentication.