Error codes
What the GameLayer API answers when something goes wrong, and what to do about it. For the Admin API's errors, see Admin API and agents.
Three answer shapes#
The GameLayer API reports problems in three shapes. Each has its own list of codes, and the numbers overlap: 1 is "achievement not found" as an error code, but "redeemed" as a claim result code. Check which shape you have before you read the code.
| Shape | When | HTTP status | What to read |
|---|---|---|---|
| Error | A request fails | 4xx or 5xx | The number in errorCode. See Error codes. |
| Rate limit | A per-key limit is reached | 429 | The text "RATE_LIMIT_EXCEEDED" in code, and the Retry-After header. See Rate limits. |
| Claim result | A claim on a prize, mystery box or raffle | 200, even when the claim fails | The number in code. See Claim result codes. |
An error:
{
"error": "Player 'user-123' exists for account 'my-account'",
"errorCode": 21
}A rate limit:
{
"code": "RATE_LIMIT_EXCEEDED",
"message": "…"
}A claim result (shortened):
{
"code": 2,
"prize": { "id": "cup-coffee", "name": "Coffee", "credits": 100 },
"player": { "player": "user-123", "credits": 5 }
}Match on the codes, not on the message text, which can change.
HTTP status codes#
200, 201 and 204 mean the request worked.
| Status | Meaning | What to do |
|---|---|---|
400 | Bad request | Check the request body and parameters |
401 | Unauthorized: the Account API key is wrong, or doesn't match the account ID | Check the api-key header and the account value |
404 | Not found: an element or player doesn't exist | Check the ID |
409 | Conflict: it already exists | Usually safe to ignore on create |
422 | The Idempotency-Key was already used for a different request (error code 111) | Use a new key for a new action |
429 | A per-key rate limit was reached ("code": "RATE_LIMIT_EXCEEDED"), or another request is updating the same player (error code 24) | Wait the number of seconds in Retry-After, then retry |
429 without Retry-After | This IP address sent more than 2,000 requests this minute. See Per IP address. | Wait for the next minute, then retry |
5xx | A problem on GameLayer's side | Retry with backoff |
Error codes#
| Code | Meaning | What to do |
|---|---|---|
1 | Achievement not found | Check the achievement ID |
2 | Event not found | Check the event exists in the dashboard |
3 | Player not found | Create the player first |
4 | Leaderboard not found | Check the leaderboard ID |
5 | Level not found | Check the level ID |
6 | Mission not found | Check the mission ID |
7 | Prize not found | Check the prize ID |
8 | Team not found | Check the team ID |
9 | Couldn't join the team | The team may be full or unavailable |
10 | Mystery box not found | Check the mystery box ID |
11 | Raffle not found | Check the raffle ID |
20 | No player given | Include the player ID |
21 | Player already exists | Safe to ignore when creating |
22 | Player limit reached on a test or free account | Delete unused players, or ask GameLayer about your account |
24 | Another request is updating this player at the same moment (HTTP 429) | Wait 1 second and retry |
25 | Invalid refresh offset | Use the format UTC+02:00: whole hours from UTC-12:00 to UTC+12:00, or UTC+14:00 |
31 | Team already exists | Safe to ignore when creating |
40 | Survey not found | Check the survey ID |
41 | Survey answers missing | Include the answers array |
42 | Player isn't eligible for the survey | They don't meet its requirements |
43 | Player hasn't completed the survey | Complete it first |
44 | Survey results aren't available yet: no player has completed the survey, or a question was added after the last completion | Show "no results yet" and try again later. It clears after the next completion. |
50 | Quiz not found | Check the quiz ID |
51 | Quiz answers missing | Include the answers array |
52 | Quiz not started | Call the start endpoint first |
53 | Quiz time ran out | The player went over the time limit |
54 | Player isn't eligible for the quiz | They don't meet its requirements |
80 | Reserved: not returned by any call | A claim outside the zone answers with claim result code 7. An event completion outside a mission's zone simply doesn't progress that mission. |
90 | Invalid voucher data | The voucher codes are missing or invalid |
100 | A leaderboard has no translation in the requested language (HTTP 404) | Request it without language, or in a language it's translated into. See Languages. |
110 | Invalid Idempotency-Key: empty, over 255 characters, outside printable ASCII, or sent twice | Send one key of 1 to 255 printable ASCII characters, such as a UUID |
111 | The Idempotency-Key was already used for a different request: another event, player or body (HTTP 422) | Use a new key for a new action |
112 | The key's record couldn't be read or written, and nothing counted | Retry with the same key after Retry-After |
Claim result codes#
Claiming a prize, opening a mystery box or buying a raffle ticket answers 200 with a code, whether or not the claim worked. Only 1 is a success. These codes are separate from the error codes above.
| Code | Status | Meaning |
|---|---|---|
1 | REDEEMED | Success. Credits deducted (none with a voucher code). |
2 | NOT_ENOUGH_CREDITS | The player doesn't have enough credits |
3 | OUT_OF_STOCK | No stock left |
5 | COUNT_EXCEEDED | The player has reached the claim limit for this period |
6 | REQUIREMENTS_NOT_MET | The player doesn't meet the requirements |
7 | OUTSIDE_ACTIONABLE_ZONE | The player is too far away, or sent no coordinates. |
8 | VOUCHER_INVALID | The voucher code is invalid, used, or for another prize |
9 | MISSION_PRIZE_NOT_CLAIMABLE | This prize is a mission reward and can't be claimed directly |
10 | VOUCHER_REQUIRED | This prize needs a voucher code |
When to retry#
A request can reach GameLayer and count while its response is lost. For event completions, an Idempotency-Key makes a retry safe. Claims and quiz and survey completions have no key, so check before you send them again.
- Reads: always safe to retry.
- Event completions: see Retrying safely. Generate a key (a UUID v4) once per player action and send it in the
Idempotency-Keyheader. Retry with the same key and the identical body. A repeat of a request that succeeded gets the same response, withX-Idempotent-Replay: true, and counts nothing again. Keys are kept for 24 hours, so retry for up to 23 hours and then drop the event. Without a key, a retry counts the event again, with its rewards, so retry only if you know the request didn't arrive. - Other completions and claims: read the player's state first, such as
GET /players/{player}/prizesafter a claim, and retry only if it didn't happen. 429: wait forRetry-After, or 1 second for error code24, then retry. WithoutRetry-After, it's the per-IP limit: wait for the next minute.- Other 4xx errors: don't retry. Fix the request.
- 5xx errors: retry reads with exponential backoff, such as 1, 2 and 4 seconds, at most 3 times. Treat writes as above.