Skip to main content

Errors

When a request fails, the response has an errors list. Each error has a message written to be read by a person and a code in extensions for your program to act on.

{
"errors": [
{
"message": "This API key does not have the read:staff permission",
"path": ["site", "orders"],
"extensions": { "code": "FORBIDDEN" }
}
],
"data": null
}

Check the body for errors whatever the HTTP status, because a response can be 200 and still carry one. Have your code branch on extensions.code. The wording of message may change.

Codes​

CodeHTTP statusMeaningWhat to do
UNAUTHENTICATED401The API key is missing, wrong or revokedCheck the Authorization header and the key
FORBIDDEN403The key cannot read that site, or lacks a permissionCheck the key's sites and permissions
BAD_USER_INPUT400An argument is wrong, such as a bad date or a range that is too longFix the request. The message says what is wrong
GRAPHQL_VALIDATION_FAILED400The query asks for a field that does not existCheck the query against the reference
GRAPHQL_PARSE_FAILED400The query is not valid GraphQLCheck the query's syntax
QUERY_TOO_LARGE400One request asks for too much at onceSplit it into smaller requests
RATE_LIMITED429Too many requests in a short timeWait, then try again. See limits
UNAVAILABLE503The service is temporarily unavailableTry again shortly
INTERNAL_SERVER_ERROR200Something went wrong on our sideTry again. If it keeps happening, contact support

Examples​

A missing or wrong key:

{
"errors": [
{
"message": "Invalid or missing API key",
"path": ["sites"],
"extensions": { "code": "UNAUTHENTICATED" }
}
],
"data": null
}

A site the key does not cover:

{
"errors": [
{
"message": "This API key cannot read that site",
"path": ["site"],
"extensions": { "code": "FORBIDDEN" }
}
],
"data": null
}

A date range that is too long:

{
"errors": [
{
"message": "Range too long - request 92 days or less at a time",
"path": ["site", "orders"],
"extensions": { "code": "BAD_USER_INPUT" }
}
],
"data": null
}

A query that names a field that does not exist. GraphQL suggests the nearest match:

{
"errors": [
{
"message": "Cannot query field \"nope\" on type \"Site\". Did you mean \"name\"?",
"extensions": { "code": "GRAPHQL_VALIDATION_FAILED" }
}
]
}

Too many requests:

{
"errors": [
{
"message": "Too many requests - slow down and try again shortly",
"extensions": { "code": "RATE_LIMITED" }
}
]
}

Retrying​

RATE_LIMITED, UNAVAILABLE and INTERNAL_SERVER_ERROR are worth retrying. Wait a little longer after each attempt, for example 1, 2, 4 then 8 seconds, and give up after a few tries.

The other codes mean the request itself needs changing, and sending it again will fail the same way.

Since every request is a read, a retry cannot do any harm.