Prerequisites
Before calling Layer’s API, you will need:- A Layer account. Reach out to your Layer contact or contact our team.
- Client credentials (
client_idandclient_secret) provided by Layer.
Environments
Layer provides two environments for development and production use:| Environment | Base URL | OAuth Scope |
|---|---|---|
| Sandbox | https://sandbox.layerfi.com | https://sandbox.layerfi.com/sandbox |
| Production | https://api.layerfi.com | https://api.layerfi.com/production |
Authenticating API requests
Layer uses OAuth 2.0’s client credentials flow. Exchange your credentials for a short-lived access token, then send that token as a bearer token on every API request.Get a bearer token
To receive an access token, send a POST request to Layer’s authorization server, passing your The authorization server will respond with your granted access token:Extract the
client_id and client_secret via HTTP Basic authentication. In the request body, include the grant_type, scope, and client_id.access_token value from the response. You’ll use this in the Authorization header for all API requests.Make an authenticated request
Include the access token as a bearer token in the The API will respond with your client name and client id:
Authorization header. You can confirm your credentials are working by calling the /whoami endpoint.Access tokens expire after 1 hour. To refresh your access token, make another call to Layer’s authorization endpoint with your
client_id and client_secret. We recommend refreshing tokens for new sets of requests rather than persisting access tokens.Business-scoped access tokens
When you build client-side experiences (for example, embedding Layer’s React components), you need a token that a browser or mobile app can safely hold. Rather than exposing yourclient_secret or a full-access token, mint a temporary token scoped to a single business on your backend and pass that to the client.
Mint a business-scoped token
From your backend, call the Create business auth token endpoint, authenticating with the bearer token from the flow above:cURL
AuthToken containing an access token scoped to that business:
session_duration is optional and sets how long, in seconds, the token is valid. It defaults to 3600 (1 hour).
Use the token in your client
Pass the business-scopedaccess_token to your client-side application. With Layer’s embedded components, provide it to LayerProvider as businessAccessToken: