Authentication
Every API request carries an access token in the Authorization header. You get the token by exchanging an API key, a Client ID and a Client secret, at the token endpoint.
Create an API key
API keys are created in the DocPayload app under Dashboard > Settings > API access > Manage keys > Generate Key. They work on paid plans and during the free plan's 14-day trial; after the trial the token endpoint answers 402 with API_ACCESS_NOT_IN_PLAN.
A key is a pair:
| Part | Example | Notes |
|---|---|---|
| Client ID | b0aa7303e6704e2188b42681d7b353fe | 32 hexadecimal characters |
| Client secret | a long random string | Shown once, when the key is generated. Copy it then: it won't be shown again |
A key expires after 180 days unless another lifetime, up to a year, is chosen when it is generated; the dialog shows its expiry date. The same dialog shows your Tenant ID, which every endpoint takes in its path.
Exchange the key for an access token
The token endpoint is POST https://api.docpayload.com/oauth2/token, the OAuth 2.0 client credentials grant
(RFC 6749, section 4.4). Any OAuth 2.0 client library can ask it for a
token: give it the token URL, the Client ID and the Client secret.
By hand, send the form grant_type=client_credentials with the Client ID and secret as HTTP Basic credentials:
curl -X POST https://api.docpayload.com/oauth2/token \
-u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \
-d grant_type=client_credentials
A client that cannot send HTTP Basic credentials may send them in the form instead, as client_id and client_secret;
one or the other, never both:
curl -X POST https://api.docpayload.com/oauth2/token \
-d grant_type=client_credentials \
-d client_id=YOUR_CLIENT_ID \
-d client_secret=YOUR_CLIENT_SECRET
Success (200 OK)
{
"access_token": "eyJhbGciOiJSUzI1NiIs...",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "document:read document:write metrics:read asset:upload document:delete"
}
| Status | Body | When |
|---|---|---|
400 | {"error": "invalid_request", ...} | The body is not a form, grant_type is missing, a parameter is repeated, or the credentials are sent both ways |
400 | {"error": "unsupported_grant_type", ...} | grant_type is not client_credentials |
400 | {"error": "invalid_scope", ...} | scope names a scope the key does not hold |
401 | {"error": "invalid_client", "error_description": "Client authentication failed."} | No credentials, a wrong Client ID or secret, an expired key, or an inactive tenant |
402 | {"error": "API_ACCESS_NOT_IN_PLAN", ...} or ACCOUNT_SUSPENDED | The plan has no API access, or an invoice is unpaid |
429 | {"error": "rate_limit_exceeded", ...} | More than 7 token requests a minute |
The token carries the scopes in scope: an API key can read, write and delete documents and templates, upload assets
and read metrics. Send scope in the form, space-separated, for a token that carries only some of them. Signing keys are
registered in the app, not with an API key.
Use the access token
Every other call, downloading a generated document included, sends the token as a Bearer token:
Authorization: Bearer YOUR_ACCESS_TOKEN
The token lasts 3600 seconds (expires_in). Keep it and reuse it for every call until it expires, then request a new one; do not request a token per call.
IP allow-list
The API access dialog also holds an optional IP allow-list. When it is set, only the listed addresses may use your keys; a call from any other address is answered 403 with IP_NOT_ALLOWED.
Security best practices
- Store the Client ID and secret in environment variables or a secret store, never in source code
- Rotate a key by generating a new one, moving your integration to it, then revoking the old one
- Set the IP allow-list to the addresses your servers call from
- Keep the access token on the server; never send the secret or the token to a browser
Error responses
| Status | Description |
|---|---|
401 Unauthorized | Missing, invalid or expired access token, or wrong Client ID or secret |
402 Payment Required | The plan has no API access, or the account is suspended for an unpaid invoice |
403 Forbidden | The token has no permission for this resource, the URL names another tenant, or the address is not on the allow-list |
429 Too Many Requests | Rate limit exceeded |