Skip to content

Errors

When a request fails, the answer has an HTTP status of 400 or more and a JSON body of type application/problem+json (RFC 9457):

{
"type": "https://docs.zemodata.com/errors/credits.insufficient",
"title": "Not enough credits",
"status": 402,
"code": "credits.insufficient",
"detail": "This request needs 500 credits; 320 are available.",
"request_id": "req_01JD3K8ZQ4V6W9XG2M5N7P0R1S",
"errors": []
}
Field Meaning
code Stable. Match on this in your code, never on title or detail.
status The HTTP status, repeated.
title A short summary of the code.
detail What happened this time, in plain words. It can change; show it to people, don’t parse it.
type A link to the page for this code, with what to do.
request_id The same as the X-Request-Id header. Quote it when you contact support.
errors For 422 validation: one item per problem, with path, code and message.

Some answers add headers: Retry-After on 429 and 503, Allow on 405.

python/errors.py
"""Read a problem response: every error has a stable `code`, a `detail` and a `request_id`."""
import json
import os
import urllib.error
import urllib.request
BASE = os.environ.get("ZEMO_API_BASE", "https://api.zemodata.com")
# An unlock without the Idempotency-Key header is refused before anything is charged.
body = {"entity": "person", "ids": ["zp_01JD3K8ZQ4V6W9XG2M5N7P0R1S"], "bundles": ["profile"]}
request = urllib.request.Request(
f"{BASE}/v1/unlock",
data=json.dumps(body).encode(),
headers={"Authorization": f"Bearer {os.environ['ZEMO_API_KEY']}", "Content-Type": "application/json"},
method="POST",
)
try:
urllib.request.urlopen(request, timeout=30)
raise SystemExit("expected a problem response")
except urllib.error.HTTPError as error:
status = error.code
problem = json.load(error) # Content-Type: application/problem+json
print(status, problem["code"]) # 400 idempotency.missing
print(problem["detail"])
print("docs:", problem["type"]) # one page per code
print("quote this to support:", problem["request_id"])
for item in problem["errors"]: # field problems, for 422 validation
print(" ", item["path"], item["code"], item["message"])
  • 4xx: the request needs to change (or the account does: credits, scopes, approval). Retrying the same request gives the same answer. The page for each code says what to do.
  • 429 and 503: wait for Retry-After seconds, then retry. See Rate limits.
  • 500: retry after a short wait with the same Idempotency-Key, so a spending call is never charged twice. If it persists, contact support with the request_id.
  • Network errors and timeouts: you don’t know whether the call went through. Retry with the same Idempotency-Key and you get the stored answer instead of a second charge.

The error codes page lists every code with its own page. The most common:

Code Status Usually means
auth.invalid_key 401 Wrong or mistyped secret
auth.scope_missing 403 The key lacks the scope for this endpoint
validation 422 A field is wrong: see errors[]
idempotency.missing 400 A spending call without Idempotency-Key
credits.insufficient 402 Buy credits or ask for less
rate_limited 429 Slow down, honour Retry-After
unavailable 503 Retry later; or a feature that needs the search engine