- Processing webhooks
- Running scheduled jobs
- Calling the API on behalf of a merchant after verifying their app token
Before You Start
Your backend needs the credentials issued when you registered your app.
The CLI’s
npm run register writes both to your backend .env. Your app manifest declares the service account under authentication.serviceAccount. See App Manifest: Authentication.
Getting a Access Token
Your backend sends its credentials to the token endpoint using HTTP Basic authentication.The token endpoint requires HTTP Basic authentication. Sending the credentials in the request body instead of the
Authorization header is rejected.Token Response
A successful request returns:Caching the Token
Access tokens are valid for approximately 24 hours. Requesting a new one on every API call adds latency and unnecessary load on the token endpoint. Hold the token in memory and request a new one shortly before it expires.This in-memory cache works for a single-instance server. If you run multiple instances behind a load balancer, use a shared cache such as Redis so they do not each hold their own token.
Calling the API
Access tokens are not tied to a merchant, so every call names the tenant it applies to in theX-Tenant-ID header. Take that value from a verified app token rather than from the incoming request. See App Token Authentication.
If a call returns 401 Unauthorized, clear the cached token and retry once with a fresh one.
Scope Enforcement
Calls made with a access token are bound by the scopes declared incapabilities.erp.api.scopes in your manifest. A call that exceeds them returns 403 Forbidden.
This holds even when a merchant is signed in. A backend that verifies an app token and then calls the API with its service account is making a machine call, so the manifest’s scopes apply rather than the merchant’s own permissions. See Scopes & Permissions.
Common Errors
The failures you are most likely to hit, and what causes them.400 Bad Request on the token request
400 Bad Request on the token request
The credentials were sent in the request body. The token endpoint requires HTTP Basic authentication, so they belong in the
Authorization header.403 Forbidden on an API call
403 Forbidden on an API call
The token is valid, but the call exceeds the scopes declared in your manifest. Add the scope your app needs and submit an updated manifest through the Partner Portal.
API calls fail with a tenant error
API calls fail with a tenant error
The
X-Tenant-ID header is missing or names a tenant your app is not installed on. Take the value from a verified app token’s urn:jtl:tenant_id claim.What’s Next?
App Token Authentication
Verify the app token that tells your backend which merchant a request belongs to.
Using Platform APIs
Call the JTL Cloud and JTL-Wawi APIs with the right headers and scoping.
Scopes & Permissions
Declare what your app can access, and understand how enforcement differs by token.
Best Practices
Production patterns for token caching, error handling, and security.