Developer Resources / Build / Quickstart

Quickstart

Create a player, complete an event, check their progress and claim a prize, in about 10 minutes. The examples are simplified; the developer kit's example clients add error handling and safe retries.

Before you start#

  • Your account ID and Account API key. See Developer setup.
  • A trial account, so test players never mix with live data. Request one through the trial form.
  • curl, or Node.js 18+ or Python 3 with requests.

The examples use the learning app example. New trial accounts come with it already set up, including these:

ElementIDSet up as
Eventcomplete-lessonAwards 10 points and 5 credits
Missionweekly-lessonsComplete complete-lesson 5 times a week. Awards 50 credits.
Prizecup-coffeeCosts 100 credits

In another account, ask your account admin to create these in the dashboard, or create them with Claude. With other IDs, change them in the examples.

With Claude connected, ask: "Create an event complete-lesson worth 10 points and 5 credits, a weekly mission weekly-lessons to complete it 5 times for 50 credits, and a prize cup-coffee costing 100 credits." Claude shows you the plan and applies it only when you confirm.

The examples use these values. Replace them with your own:

curl
export GL_API_KEY="your-account-api-key"
export GL_ACCOUNT="your-account-id"

account goes in a different place depending on the method. On GET and DELETE it's a query parameter (?account=acme). On POST and PATCH it's a field in the JSON body. In the wrong place, the API answers 401 Unauthorized.

1. Create a player#

Players represent your users in GameLayer. Use your own user ID as the player ID, so you never need a mapping table.

curl
curl -X POST https://api.gamelayer.co/api/v0/players \
  -H "api-key: $GL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "account": "'"$GL_ACCOUNT"'", "player": "user-123", "name": "Jane Doe" }'

The answer is 201 Created:

JSON
{
  "player": "user-123",
  "name": "Jane Doe",
  "tags": [],
  "category": "",
  "points": 0,
  "credits": 0,
  "team": "",
  "level": { "id": "", "name": "", "ordinal": 0 },
  "createdOn": "2026-12-01T10:30:00.000Z"
}

The player starts with 0 points and 0 credits. Points build up and drive levels and leaderboards; credits are a balance players spend on prizes. See Points and credits.

2. Complete an event#

This is the core of the integration. When a user does something in your app, call POST /events/{id}/complete. One call can progress missions, add achievement steps, level the player up, update streaks and change leaderboards: the progression cascade.

Send an Idempotency-Key with every event completion: a new UUID for each player action, kept for retries of that action. If a response is lost and you retry with the same key and body, the event isn't counted twice. See When to retry.

curl
curl -X POST https://api.gamelayer.co/api/v0/events/complete-lesson/complete \
  -H "api-key: $GL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{ "account": "'"$GL_ACCOUNT"'", "player": "user-123", "count": 1 }'

The answer (200 OK) tells you everything that happened:

JSON
{
  "event": { "id": "complete-lesson", "name": "Complete a lesson", "reward": { "points": 10, "credits": 5, "achievements": [] } },
  "player": { "name": "Jane Doe", "points": 10, "credits": 5 },
  "progress": {
    "points": { "before": 0, "earned": 10 },
    "credits": { "before": 0, "earned": 5 },
    "missions": [],
    "startedMissions": [ { "id": "weekly-lessons", "name": "Weekly lessons" } ],
    "achievements": [],
    "unlockedAchievements": [],
    "levels": { "completed": [], "started": {} },
    "completedStreaks": [],
    "activeStreaks": [],
    "rules": []
  }
}
FieldMeaning
points.earnedPoints earned in this cascade, after rule multipliers
credits.earnedCredits earned
missionsMissions completed by this event, with their rewards
startedMissionsMissions that started progressing
achievementsAchievements completed
unlockedAchievementsAchievements that gained steps but aren't complete yet
levels.completedLevels the player moved through
levels.startedThe player's new level, if they levelled up
completedStreaksStreaks that completed
activeStreaksStreaks that went up

3. Check progress#

Read a player's progress to build your UI. Each list comes back split into started and completed.

curl
curl "https://api.gamelayer.co/api/v0/players/user-123/missions?account=$GL_ACCOUNT&completion=all" \
  -H "api-key: $GL_API_KEY"

The same pattern works for /achievements, /levels, /streaks, /prizes and /events under /players/{player}.

4. Claim a prize#

List the prizes a player can claim, then claim one with their credits. Passing player returns only prizes they're eligible for and that are in stock.

curl
curl "https://api.gamelayer.co/api/v0/prizes?account=$GL_ACCOUNT&player=user-123" \
  -H "api-key: $GL_API_KEY"

curl -X POST https://api.gamelayer.co/api/v0/prizes/cup-coffee/claim \
  -H "api-key: $GL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "account": "'"$GL_ACCOUNT"'", "player": "user-123" }'

A claim always answers with a code. 1 means the prize was redeemed and the credits deducted. Any other code explains why not, such as 2 for not enough credits. See Claim result codes.

After one lesson the player has 5 credits, so this first claim answers 2. Complete complete-lesson 20 times, or pass "count": 20, and claim again to get 1.

Next steps#