get
https://www.locally.com/headless/api/1.0/session/id
Get a session ID. A session is used to persist user data when making API calls (e.g. location and cart items).
Request Parameters
🏷️ header · unmarked parameters are query params
| Parameter | Type | Required | Description |
|---|---|---|---|
Locally-Api-Token 🏷️ | string | Yes | Locally API token must be passed in the header to authenticate the API consumer. |
Example Request
curl 'https://www.locally.com/headless/api/1.0/session/id' \
--header 'Locally-Api-Token: {{API_TOKEN}}'const response = await fetch('https://www.locally.com/headless/api/1.0/session/id', {
headers: {
'Locally-Api-Token': '{{API_TOKEN}}'
}
});
const payload = await response.json();
const sessionId = payload.data.session.id;import requests
response = requests.get(
'https://www.locally.com/headless/api/1.0/session/id',
headers={'Locally-Api-Token': '{{API_TOKEN}}'}
)
payload = response.json()
session_id = payload['data']['session']['id']Pass the returned data.session.id as the Locally-Api-Session-Id header on subsequent requests to persist the shopper's data (e.g. location and cart items) between API calls. Session IDs can expire — if an expired ID is passed, a new one is returned in the payload.
Example Response
{
"success": true,
"data": {
"session": {
"id": "abc999"
}
},
"msg": ""
}Response Explanation
success— Whether the request was processed. On failure it isfalse,msgcarries the error text, and anerror_codefield is added to the envelope.data.session— Included on every Headless API response, not just this endpoint. The backing server session expires after 120 minutes of inactivity, so long-running integrations should re-read the ID from each response.data.session.id— Session ID returned on every response. Pass it as theLocally-Api-Session-Idheader on later calls to persist location and cart state; expired or missing IDs are replaced with fresh ones.msg— Human-readable envelope message: an empty string on success, the error text whensuccessisfalse(which also adds anerror_codefield).
200Successful
400Bad Request
401Unauthorized
402Request Failed
403Forbidden
404Not Found
429Too Many Requests
500Server Error

