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.
"""Read a problem response: every error has a stable `code`, a `detail` and a `request_id`."""
import jsonimport osimport urllib.errorimport 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.missingprint(problem["detail"])print("docs:", problem["type"]) # one page per codeprint("quote this to support:", problem["request_id"])for item in problem["errors"]: # field problems, for 422 validation print(" ", item["path"], item["code"], item["message"])// Read a problem response: every error has a stable `code`, a `detail` and a `request_id`.
const BASE = process.env.ZEMO_API_BASE ?? "https://api.zemodata.com";
// An unlock without the Idempotency-Key header is refused before anything is charged.const response = await fetch(`${BASE}/v1/unlock`, { method: "POST", headers: { Authorization: `Bearer ${process.env.ZEMO_API_KEY}`, "Content-Type": "application/json" }, body: JSON.stringify({ entity: "person", ids: ["zp_01JD3K8ZQ4V6W9XG2M5N7P0R1S"], bundles: ["profile"] }),});if (response.ok) throw new Error("expected a problem response");
const problem = await response.json(); // Content-Type: application/problem+jsonconsole.log(response.status, problem.code); // 400 idempotency.missingconsole.log(problem.detail);console.log("docs:", problem.type); // one page per codeconsole.log("quote this to support:", problem.request_id);for (const item of problem.errors) console.log(" ", item.path, item.code, item.message); // for 422 validationif (problem.code !== "idempotency.missing") process.exit(1);# Read a problem response: every error has a stable `code`, a `detail` and a `request_id`.set -euo pipefailBASE="${ZEMO_API_BASE:-https://api.zemodata.com}"
# An unlock without the Idempotency-Key header is refused before anything is charged.# --write-out prints the HTTP status after the problem body (application/problem+json).curl --silent --show-error --write-out '\nHTTP %{http_code}\n' \ -H "Authorization: Bearer $ZEMO_API_KEY" \ -H "Content-Type: application/json" \ -d '{"entity": "person", "ids": ["zp_01JD3K8ZQ4V6W9XG2M5N7P0R1S"], "bundles": ["profile"]}' \ "$BASE/v1/unlock"Handling errors well
Section titled “Handling errors well”- 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-Afterseconds, 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 therequest_id. - Network errors and timeouts: you don’t know whether the call went through. Retry with the same
Idempotency-Keyand you get the stored answer instead of a second charge.
All codes
Section titled “All codes”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 |