Appearance
Platform API
Authentication
Every PAPI request is authenticated with an HMAC-SHA256 signature. No OAuth, no session cookies.
Required headers
| Header | Description |
|---|---|
x-api-key | The UUID API key issued to you. See API Keys & Scopes. |
x-timestamp | Current time as Unix milliseconds, sent as a string. |
x-nonce | A unique value per request (a UUID works well). Reusing a nonce for the same key is rejected. |
x-signature | Hex-encoded HMAC-SHA256 signature over the canonical string below. |
Canonical string construction
Build the following newline-joined (\n) string, then sign it:
text
<x-timestamp>
<x-nonce>
<UPPERCASE_METHOD>
<PATH_WITH_QUERY>
<SHA256_HEX_OF_RAW_BODY>Rules:
- Method is uppercase, e.g.
POST,GET. - Path includes the query string and excludes scheme/host, e.g.
/v1/accounts?limit=10. - Body hash is the SHA-256 hex digest of the exact raw request bytes actually sent. For requests with no body, hash an empty byte string.
- The signature itself is
HMAC-SHA256(canonicalString, secret), hex-encoded.
Computing the signature
ts
import { createHash, createHmac } from 'node:crypto';
function sign(params: {
method: string;
pathWithQuery: string;
rawBody: string;
timestamp: string;
nonce: string;
secret: string;
}): string {
const bodySha256 = createHash('sha256').update(params.rawBody).digest('hex');
const canonical = [
params.timestamp,
params.nonce,
params.method.toUpperCase(),
params.pathWithQuery,
bodySha256,
].join('\n');
return createHmac('sha256', params.secret).update(canonical).digest('hex');
}Timestamp window
Requests must arrive with x-timestamp within a configured window of the server's clock, 5 minutes (300000 ms) by default. Requests outside this window are rejected, so keep client clocks NTP-synced.
Nonce & replay protection
Nonces are tracked per API key. Reusing a nonce for the same key, even with a valid signature, is rejected as a replay attempt. Generate a fresh nonce (a UUID, or a high-resolution timestamp plus random suffix) for every request.
Error responses
All authentication failures return the same generic response, by design:
json
{
"statusCode": 401,
"error": "Unauthorized",
"message": "Invalid API credentials"
}This applies uniformly to a missing header, a malformed or stale timestamp, an unknown or disabled API key, a reused nonce, or an invalid signature. The response intentionally does not distinguish between these cases. This prevents an attacker (or a buggy client) from using error responses to enumerate valid keys, timestamps, or nonces. Don't rely on the response shape to distinguish failure modes; use the checklist below to debug instead.
Troubleshooting checklist
If you're getting 401 Invalid API credentials and believe your request should be valid, check:
- Clock skew. Is your
x-timestampwithin 5 minutes of real time? - Raw vs. re-serialized body. If you parse the JSON body and re-serialize it before hashing, whitespace or key-ordering differences will silently change the hash. Sign the exact bytes you send on the wire, not a re-stringified copy.
- Query string inclusion. The signed path must include the query string exactly as sent, including parameter order.
- Method casing. The canonical string uses the uppercase HTTP method.
- Nonce reuse. Retried requests need a new nonce, not the same one.
See also
- Getting Started: a full worked request.
- API Keys & Scopes: how keys are issued.
- Errors & Conventions: other status codes and conventions.
- Resource reference: Accounts, Persons, Organizations, Transfers, System.