Send your first event
Before you start
Section titled “Before you start”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.
1. Obtain an access token
Section titled “1. Obtain an access token”Set STREAKLINE_CLIENT_ID and STREAKLINE_CLIENT_SECRET in your local server environment, then exchange them:
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.
2. Send an event over REST
Section titled “2. Send an event over REST”Use your application’s stable internal user UUID and a unique ID for this occurrence:
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.
3. Use TypeScript
Section titled “3. Use TypeScript”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);Next steps
Section titled “Next steps”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.