Documentation Index Fetch the complete documentation index at: https://developers.firmly.ai/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Browser Session is the authentication endpoint that serves as the starting point for all Cart API integrations. It exchanges your Application ID for an access token that authenticates subsequent API calls.
Authentication
Your Application ID provided by Firmly
Request Body (Optional)
An expired access token (valid up to 1 week after expiration) to renew
Response
Indicates whether or not a new device was created for this session
The JWT access token to use in x-firmly-authorization header for all API calls
Number of seconds until the token expires (typically 3600)
Unix timestamp when the token expires
Unique identifier for this device session
Code Examples
curl -X POST https://api.firmly.work/api/v1/browser-session \
-H "x-firmly-app-id: YOUR_APPLICATION_ID"
{
"device_created" : true ,
"access_token" : "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJkZXZpY2VfaWQiOiI4MmIxMDUyMi01NDgzLTQ3MTktYjU5OS02ZDc4YjEyODI3ZjAiLCJhcHBfaWQiOiJhcHAtMTIzNDU2IiwiZXhwIjoxNjg4OTk4NTcyLCJpYXQiOjE2ODg5OTQ5NzJ9.signature" ,
"expires_in" : 3600 ,
"expires" : 1688998572 ,
"device_id" : "82b10522-5483-4719-b599-6d78b12827f0"
}
Token Renewal
You can renew an expired token up to 1 week after expiration:
Using Body Parameter
Using Cookie
curl -X POST https://api.firmly.work/api/v1/browser-session \
-H "x-firmly-app-id: YOUR_APPLICATION_ID" \
-H "Content-Type: application/json" \
-d '{"access_token": "EXPIRED_TOKEN"}'
Using the Access Token
After obtaining the access token, include it in all API requests:
curl -X GET https://api.firmly.work/api/v2/domains/staging.luma.gift/cart \
-H "x-firmly-authorization: YOUR_ACCESS_TOKEN"
Error Responses
Invalid or missing Application ID {
"error" : "InvalidAppId" ,
"message" : "Application ID is invalid or not found"
}
Expired token cannot be renewed (older than 1 week) {
"error" : "TokenExpired" ,
"message" : "Token is too old to renew"
}
Best Practices
Token Refresh : Implement automatic token refresh before expiration. The authorization token represents the user’s device. It should be stored with the user; not with the backend
Error Handling : Handle token expiration gracefully with retry logic
Implementation Example
class FirmlyAuth {
constructor ( appId ) {
this . appId = appId ;
this . token = null ;
this . expiresAt = null ;
}
async getToken () {
// Return existing token if still valid
if ( this . token && Date . now () < this . expiresAt ) {
return this . token ;
}
// Get new token
const response = await fetch ( 'https://api.firmly.work/api/v1/browser-session' , {
method: 'POST' ,
headers: { 'x-firmly-app-id' : this . appId }
});
const data = await response . json ();
this . token = data . access_token ;
this . expiresAt = data . expires * 1000 ; // Convert to milliseconds
return this . token ;
}
}
Next Steps
After authentication, you can: