Authentication
Every call to https://api.zemodata.com/v1 carries API credentials. You create them in the portal
under API keys. Each key has one authentication mode; your plan decides which modes you may
use (a mode your plan doesn’t allow answers auth.mode_not_allowed).
| Mode | Send | Good for |
|---|---|---|
| Bearer secret | Authorization: Bearer zd_live_sk_… |
Getting started, server-side code |
| Signed requests | Key ID + an HMAC signature per request | Production: the secret never travels |
| OAuth client credentials | A short-lived token from POST /oauth/token |
Enterprise plans, many services |
Test and live keys
Section titled “Test and live keys”- Test keys (
zd_test_…) read a made-up test dataset. They never spend credits; spending calls report what a live key would pay inmeta.credits_would_charge. - Live keys (
zd_live_…) read real data and spend credits. You can create them once your email is confirmed and your account approved. Owners and admins need two-step sign-in first.
Secrets are shown once, when the key is created or rotated. If you lose one, rotate the key: the old secret keeps working for the overlap time you choose, so you can switch without downtime.
Credential formats
Section titled “Credential formats”| Credential | Format |
|---|---|
| Bearer or signing secret | zd_{env}_sk_ + 40 letters and digits |
| Key ID (public) | zd_{env}_kid_ + 20 letters and digits |
| OAuth client ID / secret | zd_{env}_cid_ + 20 / zd_{env}_cs_ + 40 |
{env} is test or live. The prefixes are registered with GitHub secret scanning: a secret pushed to a
public repository is revoked automatically and the organization’s owners get an email.
Scopes
Section titled “Scopes”A key can only call endpoints its scopes allow. A missing scope answers
403 auth.scope_missing. Scopes can’t be added to an existing key.
| Scope | Allows |
|---|---|
search |
Fields, taxonomy and geo lookups (and search and count, when they are live) |
enrich |
POST /v1/person/enrich, POST /v1/company/enrich |
unlock |
POST /v1/unlock, POST /v1/estimate |
search, unlock or enrich |
Records by ID (GET /v1/person/{id}, GET /v1/company/{id}): any one of them |
usage_read |
GET /v1/usage |
ledger_read |
GET /v1/credits, GET /v1/ledger |
bulk |
Bulk jobs (/v1/bulk/jobs*) |
webhooks |
Reserved for managing webhooks with a key (coming soon; manage webhooks in the portal today) |
Keys can also be narrowed to some data products, an IP allowlist (others get
auth.ip_not_allowed), an expiry date, a rate limit and a daily credit cap.
Bearer secret
Section titled “Bearer secret”Send the secret in the Authorization header. GET /v1/whoami is free and needs no scope, so it is the
easiest way to check a key.
"""Check that your API key works: GET /v1/whoami (free, needs no scope)."""
import jsonimport osimport urllib.request
BASE = os.environ.get("ZEMO_API_BASE", "https://api.zemodata.com")SECRET = os.environ["ZEMO_API_KEY"] # zd_test_sk_… or zd_live_sk_…
request = urllib.request.Request( f"{BASE}/v1/whoami", headers={"Authorization": f"Bearer {SECRET}"},)with urllib.request.urlopen(request, timeout=30) as response: me = json.load(response)
print("organization:", me["org_id"])print("key:", me["public_id"], f"({me['env']}, {me['auth_mode']})")print("scopes:", ", ".join(me["scopes"]))print("products:", ", ".join(me["products"]) or "(all granted products)")// Check that your API key works: GET /v1/whoami (free, needs no scope). Node 18 or later.
const BASE = process.env.ZEMO_API_BASE ?? "https://api.zemodata.com";const SECRET = process.env.ZEMO_API_KEY; // zd_test_sk_… or zd_live_sk_…
const response = await fetch(`${BASE}/v1/whoami`, { headers: { Authorization: `Bearer ${SECRET}` },});if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`);const me = await response.json();
console.log("organization:", me.org_id);console.log("key:", me.public_id, `(${me.env}, ${me.auth_mode})`);console.log("scopes:", me.scopes.join(", "));console.log("products:", me.products.join(", ") || "(all granted products)");# Check that your API key works: GET /v1/whoami (free, needs no scope).set -euo pipefailBASE="${ZEMO_API_BASE:-https://api.zemodata.com}"
curl --silent --show-error --fail-with-body \ -H "Authorization: Bearer $ZEMO_API_KEY" \ "$BASE/v1/whoami"echoSigned requests
Section titled “Signed requests”The secret stays on your side. Every request carries four headers:
X-Zemo-Key-Id: zd_live_kid_Q8f3…X-Zemo-Timestamp: 1795439785X-Zemo-Nonce: 6f1c2e9a8b7d4c3e2f1a0b9c8d7e6f5aX-Zemo-Signature: v1=<hex HMAC-SHA256(secret, canonical string)>The canonical string is six lines joined with \n (UTF-8, no newline at the end):
METHOD upper case: GET, POST/v1/path the path, without the querysorted_query key=value pairs, RFC 3986 encoded, sorted by key then value, joined with & (an empty line when there is no query)TIMESTAMP Unix time in secondsNONCE 16 to 64 characters, new for every requesthex(SHA-256(body)) of the exact bytes you send (SHA-256 of the empty string when there is none)Rules that trip people up:
- The timestamp must be within 300 seconds of our clock, in seconds, not milliseconds
(
auth.timestamp_skew). - A nonce can be used once in 10 minutes, retries included
(
auth.replayed). - In the query, a
+means a space. Decode every name and value, then encode it again with RFC 3986 rules (%20for a space; letters, digits and-._~stay as they are) before sorting. - Hash the body bytes you actually send, not a re-serialised copy of your JSON.
"""Call the API in signed mode: key ID + secret, an HMAC-SHA256 signature per request."""
import hashlibimport hmacimport jsonimport osimport secretsimport timeimport urllib.parseimport urllib.request
def _encode(value: str) -> str: return urllib.parse.quote(value, safe="-._~") # RFC 3986: a space is %20
def canonical_string(method: str, path: str, query: str, timestamp: str, nonce: str, body: bytes) -> str: """Six lines: method, path, sorted query, timestamp, nonce, SHA-256 of the body.""" pairs = sorted( (_encode(key), _encode(value)) for key, value in urllib.parse.parse_qsl(query, keep_blank_values=True) ) return "\n".join( [ method.upper(), path, "&".join(f"{key}={value}" for key, value in pairs), timestamp, nonce, hashlib.sha256(body).hexdigest(), ] )
def signature(secret: str, canonical: str) -> str: return "v1=" + hmac.new(secret.encode(), canonical.encode(), hashlib.sha256).hexdigest()
def signed_request(method: str, url: str, body: bytes = b"") -> urllib.request.Request: parts = urllib.parse.urlsplit(url) timestamp = str(int(time.time())) # seconds, not milliseconds nonce = secrets.token_hex(16) # new for every request, retries included canonical = canonical_string(method, parts.path, parts.query, timestamp, nonce, body) headers = { "X-Zemo-Key-Id": os.environ["ZEMO_KEY_ID"], # zd_test_kid_… "X-Zemo-Timestamp": timestamp, "X-Zemo-Nonce": nonce, "X-Zemo-Signature": signature(os.environ["ZEMO_API_SECRET"], canonical), } if body: headers["Content-Type"] = "application/json" return urllib.request.Request(url, data=body or None, headers=headers, method=method)
if __name__ == "__main__": base = os.environ.get("ZEMO_API_BASE", "https://api.zemodata.com") with urllib.request.urlopen(signed_request("GET", f"{base}/v1/whoami"), timeout=30) as response: me = json.load(response) print("signed in as", me["public_id"], "with", me["auth_mode"], "requests")// Call the API in signed mode: key ID + secret, an HMAC-SHA256 signature per request.import { createHash, createHmac, randomBytes } from "node:crypto";import { pathToFileURL } from "node:url";
// RFC 3986: encodeURIComponent plus the five characters it leaves alone. A space is %20.const encode = (value) => encodeURIComponent(value).replace(/[!'()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
/** Six lines: method, path, sorted query, timestamp, nonce, SHA-256 of the body. */export function canonicalString(method, path, query, timestamp, nonce, body) { const pairs = [...new URLSearchParams(query)] // decodes, and reads "+" as a space .map(([key, value]) => [encode(key), encode(value)]) .sort(([k1, v1], [k2, v2]) => (k1 < k2 ? -1 : k1 > k2 ? 1 : v1 < v2 ? -1 : v1 > v2 ? 1 : 0)); return [ method.toUpperCase(), path, pairs.map(([key, value]) => `${key}=${value}`).join("&"), timestamp, nonce, createHash("sha256").update(body).digest("hex"), ].join("\n");}
export function signature(secret, canonical) { return "v1=" + createHmac("sha256", secret).update(canonical).digest("hex");}
export async function signedFetch(method, url, body = "") { const { pathname, search } = new URL(url); const timestamp = String(Math.floor(Date.now() / 1000)); // seconds, not milliseconds const nonce = randomBytes(16).toString("hex"); // new for every request, retries included const canonical = canonicalString(method, pathname, search.slice(1), timestamp, nonce, body); const headers = { "X-Zemo-Key-Id": process.env.ZEMO_KEY_ID, // zd_test_kid_… "X-Zemo-Timestamp": timestamp, "X-Zemo-Nonce": nonce, "X-Zemo-Signature": signature(process.env.ZEMO_API_SECRET, canonical), }; if (body) headers["Content-Type"] = "application/json"; return fetch(url, { method, headers, body: body || undefined });}
if (import.meta.url === pathToFileURL(process.argv[1]).href) { const base = process.env.ZEMO_API_BASE ?? "https://api.zemodata.com"; const response = await signedFetch("GET", `${base}/v1/whoami`); if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`); const me = await response.json(); console.log("signed in as", me.public_id, "with", me.auth_mode, "requests");}# Call the API in signed mode with curl and openssl: GET /v1/whoami.set -euo pipefailBASE="${ZEMO_API_BASE:-https://api.zemodata.com}"
method="GET"path="/v1/whoami"query="" # sorted key=value pairs, RFC 3986 encodedbody="" # the exact bytes you sendtimestamp="$(date +%s)" # seconds, not millisecondsnonce="$(openssl rand -hex 16)" # new for every request, retries includedbody_sha256="$(printf '%s' "$body" | openssl dgst -sha256 -hex | sed 's/^.* //')"
canonical="$(printf '%s\n%s\n%s\n%s\n%s\n%s' "$method" "$path" "$query" "$timestamp" "$nonce" "$body_sha256")"signature="v1=$(printf '%s' "$canonical" | openssl dgst -sha256 -hmac "$ZEMO_API_SECRET" -hex | sed 's/^.* //')"
curl --silent --show-error --fail-with-body \ -H "X-Zemo-Key-Id: $ZEMO_KEY_ID" \ -H "X-Zemo-Timestamp: $timestamp" \ -H "X-Zemo-Nonce: $nonce" \ -H "X-Zemo-Signature: $signature" \ "$BASE$path"echoTest vectors
Section titled “Test vectors”Check your own implementation against these. The secret is a made-up test value; all three samples above reproduce every vector (they are tested against them).
secret: zd_test_sk_0123456789abcdefghijABCDEFGHIJ0123456789
GET /v1/whoami, no query, no body, timestamp 1795439785, nonce 6f1c2e9a8b7d4c3e2f1a0b9c8d7e6f5acanonical: GET\n/v1/whoami\n\n1795439785\n6f1c2e9a8b7d4c3e2f1a0b9c8d7e6f5a\ne3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855signature: v1=e182740a3557ca128a9450b165ee0d9e0beb1d924215bd3ef6b7c12dba46f8ad
GET /v1/person/search?q=caf%C3%A9+bar&path=a%2Fb&keep=~._-&space=x%20ytimestamp 1795439787, nonce 0123456789abcdefcanonical: GET\n/v1/person/search\nkeep=~._-&path=a%2Fb&q=caf%C3%A9%20bar&space=x%20y\n1795439787\n0123456789abcdef\ne3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855signature: v1=c1b480fbf97a444053cd470563ecea9a0539f13ad9c497ff0ef363f9a6fe4e2b
POST /v1/person/enrich, body {"email": "ada@example.com", "min_likelihood": 6}timestamp 1795439788, nonce a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6canonical: POST\n/v1/person/enrich\n\n1795439788\na1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6\n6a2a1499942f647f2aa3f083928f132f0e29991ce4d11325f114011d825151e5signature: v1=e54b04debabce4e8a92fc030cf7e61bc4ed86e4f90b4462d112e344c85355cdeSigned-mode errors: auth.signature_invalid,
auth.timestamp_skew, auth.replayed,
auth.mode_not_allowed.
OAuth client credentials
Section titled “OAuth client credentials”An OAuth app is a key with the oauth mode. Its client ID is zd_{env}_cid_… and its secret
zd_{env}_cs_…. Exchange them for an access token, then send the token as a bearer:
curl -s -u "$ZEMO_CLIENT_ID:$ZEMO_CLIENT_SECRET" \ -d "grant_type=client_credentials&scope=enrich unlock" \ https://api.zemodata.com/oauth/token# {"access_token": "eyJ…", "token_type": "Bearer", "expires_in": 900, "scope": "enrich unlock"}
curl -s -H "Authorization: Bearer eyJ…" https://api.zemodata.com/v1/whoami- Tokens last 900 seconds. Ask for a new one when it expires (there is no refresh token).
- The scopes you ask for must be within the app’s scopes.
- Tokens are JWTs signed with RS256; the public keys are at
/.well-known/jwks.json. Revoking the app stops tokens already issued. - Errors carry the OAuth
errorfield as well as the problemcode: a wrong client ID or secret is401witherror: invalid_client; a bad grant type or scope is400witherror: unsupported_grant_typeorinvalid_scope.