Essentials

Authentication

Every WhiteBooks API call is authenticated with OAuth 2.0. You exchange your application credentials for a short-lived bearer token, then send that token with each request.

Your credentials

After signing up you receive three values. Treat the secret like a password.

CredentialSent asPurpose
x-api-keyHeaderIdentifies and rate-limits your application.
client_idHeaderPublic identifier for the OAuth client.
client_secretHeaderPrivate secret used only to mint tokens.
Keep your secret server-side
Never ship client_secret in browser or mobile code. Mint tokens from your backend and pass only the resulting bearer token to clients if needed.

1 · Request an access token

Call the authentication endpoint with your credentials in the headers:

1curl -X GET "https://apisandbox.whitebooks.in/authentication/authtoken" \
2 -H "x-api-key: YOUR_API_KEY" \
3 -H "client_id: YOUR_CLIENT_ID" \
4 -H "client_secret: YOUR_CLIENT_SECRET"

A successful response returns an access_token, a token_type of Bearer, and expires_in seconds.

2 · Authenticate requests

Attach the token in the Authorization header (and keep sending x-api-key) on every call:

1curl -X POST "https://apisandbox.whitebooks.in/einvoice/type/GENERATE/version/V1_03" \
2 -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
3 -H "x-api-key: YOUR_API_KEY" \
4 -H "Content-Type: application/json" \
5 -d '{ "invoice": { } }'

Token lifetime & refresh

Access tokens are valid for one hour (expires_in: 3600). When a token expires the API returns 401 Unauthorized — request a new token and retry. Our official SDKs cache and refresh tokens for you automatically.

Don’t mint a token per request
Re-use a token until it’s close to expiry. Caching it avoids unnecessary auth calls and keeps you well within rate limits.

Production security

Production accounts can layer on additional controls:

  • TLS 1.2+ is enforced on all endpoints (TLS 1.3 preferred).
  • IP allow-listing restricts which addresses may use your keys.
  • SHA256-RSA request signing adds payload integrity for sensitive flows.
  • Role-based access control scopes what each key can do.

Common auth errors

StatusMeaningFix
401Token missing, invalid, or expiredRequest a fresh token and retry.
403Key lacks permission or IP not allow-listedCheck RBAC scopes and allow-list.
429Rate limit exceededBack off and retry after the reset window.