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:
| Element | ID | Set up as |
|---|---|---|
| Event | complete-lesson | Awards 10 points and 5 credits |
| Mission | weekly-lessons | Complete complete-lesson 5 times a week. Awards 50 credits. |
| Prize | cup-coffee | Costs 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:
export GL_API_KEY="your-account-api-key"
export GL_ACCOUNT="your-account-id"import { randomUUID } from "node:crypto";
const BASE_URL = "https://api.gamelayer.co/api/v0";
const API_KEY = process.env.GL_API_KEY;
const ACCOUNT = process.env.GL_ACCOUNT;import os, requests
BASE_URL = "https://api.gamelayer.co/api/v0"
ACCOUNT = os.environ["GL_ACCOUNT"]
headers = {"api-key": os.environ["GL_API_KEY"], "Content-Type": "application/json"}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 -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" }'const res = await fetch(`${BASE_URL}/players`, {
method: "POST",
headers: { "api-key": API_KEY, "Content-Type": "application/json" },
body: JSON.stringify({ account: ACCOUNT, player: "user-123", name: "Jane Doe" }),
});
console.log(await res.json());res = requests.post(f"{BASE_URL}/players", headers=headers, json={
"account": ACCOUNT, "player": "user-123", "name": "Jane Doe",
})
print(res.json())The answer is 201 Created:
{
"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 -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 }'const res = await fetch(`${BASE_URL}/events/complete-lesson/complete`, {
method: "POST",
headers: {
"api-key": API_KEY,
"Content-Type": "application/json",
"Idempotency-Key": randomUUID(), // reuse it if you retry this action
},
body: JSON.stringify({ account: ACCOUNT, player: "user-123", count: 1 }),
});
const result = await res.json();
console.log("Points earned:", result.progress.points.earned);
console.log("Missions completed:", result.progress.missions);import uuid
key = str(uuid.uuid4()) # reuse it if you retry this action
res = requests.post(f"{BASE_URL}/events/complete-lesson/complete",
headers={**headers, "Idempotency-Key": key}, json={
"account": ACCOUNT, "player": "user-123", "count": 1,
})
result = res.json()
print("Points earned:", result["progress"]["points"]["earned"])
print("Missions completed:", result["progress"]["missions"])The answer (200 OK) tells you everything that happened:
{
"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": []
}
}| Field | Meaning |
|---|---|
points.earned | Points earned in this cascade, after rule multipliers |
credits.earned | Credits earned |
missions | Missions completed by this event, with their rewards |
startedMissions | Missions that started progressing |
achievements | Achievements completed |
unlockedAchievements | Achievements that gained steps but aren't complete yet |
levels.completed | Levels the player moved through |
levels.started | The player's new level, if they levelled up |
completedStreaks | Streaks that completed |
activeStreaks | Streaks 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 "https://api.gamelayer.co/api/v0/players/user-123/missions?account=$GL_ACCOUNT&completion=all" \
-H "api-key: $GL_API_KEY"const res = await fetch(`${BASE_URL}/players/user-123/missions?account=${ACCOUNT}&completion=all`, {
headers: { "api-key": API_KEY },
});
const { missions } = await res.json();
console.log("Started:", missions.started, "Completed:", missions.completed);res = requests.get(f"{BASE_URL}/players/user-123/missions", headers=headers,
params={"account": ACCOUNT, "completion": "all"})
missions = res.json()["missions"]
print("Started:", missions["started"], "Completed:", missions["completed"])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 "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" }'const res = await fetch(`${BASE_URL}/prizes/cup-coffee/claim`, {
method: "POST",
headers: { "api-key": API_KEY, "Content-Type": "application/json" },
body: JSON.stringify({ account: ACCOUNT, player: "user-123" }),
});
const claim = await res.json();
console.log("Result code:", claim.code, "Credits left:", claim.player.credits);res = requests.post(f"{BASE_URL}/prizes/cup-coffee/claim", headers=headers,
json={"account": ACCOUNT, "player": "user-123"})
claim = res.json()
print("Result code:", claim["code"], "Credits left:", claim["player"]["credits"])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#
- Integration guide: player lifecycle, event tracking, prize stores, leaderboards, quizzes and more
- Concepts: how the pieces fit together
- GameLayer API reference: every endpoint
- Developer kit: the Postman collection and example clients