Get 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

ParameterTypeRequiredDescription
Locally-Api-Token 🏷️stringYesLocally 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 is false, msg carries the error text, and an error_code field 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 the Locally-Api-Session-Id header 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 when success is false (which also adds an error_code field).
Headers
string
required

Locally API token must be passed in the header to authenticate the API consumer

Responses
200

Successful

400

Bad Request

401

Unauthorized

402

Request Failed

403

Forbidden

404

Not Found

429

Too Many Requests

500

Server Error

Language
LoadingLoading…
Response
Click Try It! to start a request and see the response here!