Developer Resources / Build / Error codes

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.

ShapeWhenHTTP statusWhat to read
ErrorA request fails4xx or 5xxThe number in errorCode. See Error codes.
Rate limitA per-key limit is reached429The text "RATE_LIMIT_EXCEEDED" in code, and the Retry-After header. See Rate limits.
Claim resultA claim on a prize, mystery box or raffle200, even when the claim failsThe number in code. See Claim result codes.

An error:

JSON
{
  "error": "Player 'user-123' exists for account 'my-account'",
  "errorCode": 21
}

A rate limit:

JSON
{
  "code": "RATE_LIMIT_EXCEEDED",
  "message": "…"
}

A claim result (shortened):

JSON
{
  "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.

StatusMeaningWhat to do
400Bad requestCheck the request body and parameters
401Unauthorized: the Account API key is wrong, or doesn't match the account IDCheck the api-key header and the account value
404Not found: an element or player doesn't existCheck the ID
409Conflict: it already existsUsually safe to ignore on create
422The Idempotency-Key was already used for a different request (error code 111)Use a new key for a new action
429A 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-AfterThis IP address sent more than 2,000 requests this minute. See Per IP address.Wait for the next minute, then retry
5xxA problem on GameLayer's sideRetry with backoff

Error codes#

CodeMeaningWhat to do
1Achievement not foundCheck the achievement ID
2Event not foundCheck the event exists in the dashboard
3Player not foundCreate the player first
4Leaderboard not foundCheck the leaderboard ID
5Level not foundCheck the level ID
6Mission not foundCheck the mission ID
7Prize not foundCheck the prize ID
8Team not foundCheck the team ID
9Couldn't join the teamThe team may be full or unavailable
10Mystery box not foundCheck the mystery box ID
11Raffle not foundCheck the raffle ID
20No player givenInclude the player ID
21Player already existsSafe to ignore when creating
22Player limit reached on a test or free accountDelete unused players, or ask GameLayer about your account
24Another request is updating this player at the same moment (HTTP 429)Wait 1 second and retry
25Invalid refresh offsetUse the format UTC+02:00: whole hours from UTC-12:00 to UTC+12:00, or UTC+14:00
31Team already existsSafe to ignore when creating
40Survey not foundCheck the survey ID
41Survey answers missingInclude the answers array
42Player isn't eligible for the surveyThey don't meet its requirements
43Player hasn't completed the surveyComplete it first
44Survey results aren't available yet: no player has completed the survey, or a question was added after the last completionShow "no results yet" and try again later. It clears after the next completion.
50Quiz not foundCheck the quiz ID
51Quiz answers missingInclude the answers array
52Quiz not startedCall the start endpoint first
53Quiz time ran outThe player went over the time limit
54Player isn't eligible for the quizThey don't meet its requirements
80Reserved: not returned by any callA claim outside the zone answers with claim result code 7. An event completion outside a mission's zone simply doesn't progress that mission.
90Invalid voucher dataThe voucher codes are missing or invalid
100A leaderboard has no translation in the requested language (HTTP 404)Request it without language, or in a language it's translated into. See Languages.
110Invalid Idempotency-Key: empty, over 255 characters, outside printable ASCII, or sent twiceSend one key of 1 to 255 printable ASCII characters, such as a UUID
111The Idempotency-Key was already used for a different request: another event, player or body (HTTP 422)Use a new key for a new action
112The key's record couldn't be read or written, and nothing countedRetry 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.

CodeStatusMeaning
1REDEEMEDSuccess. Credits deducted (none with a voucher code).
2NOT_ENOUGH_CREDITSThe player doesn't have enough credits
3OUT_OF_STOCKNo stock left
5COUNT_EXCEEDEDThe player has reached the claim limit for this period
6REQUIREMENTS_NOT_METThe player doesn't meet the requirements
7OUTSIDE_ACTIONABLE_ZONEThe player is too far away, or sent no coordinates.
8VOUCHER_INVALIDThe voucher code is invalid, used, or for another prize
9MISSION_PRIZE_NOT_CLAIMABLEThis prize is a mission reward and can't be claimed directly
10VOUCHER_REQUIREDThis 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-Key header. Retry with the same key and the identical body. A repeat of a request that succeeded gets the same response, with X-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}/prizes after a claim, and retry only if it didn't happen.
  • 429: wait for Retry-After, or 1 second for error code 24, then retry. Without Retry-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.