Linking customers

Tell Lean which customer a session belongs to, and turn on the customer-based labels.

The SDK doesn't know who your user is, and never sends a user id. On its own, Lean can only compare a device with that device's history. When your backend tells Lean which customer a session belongs to, Lean can also compare the device with that customer's other devices, locations and sessions. This turns on the customer-based labels.

When to link

Link the session as soon as your backend knows who the user is, typically right after a successful login, and before you read the assessment for a sensitive action.

The customer_id is the Lean customer id your application already uses, from the Create Customer API. It must belong to the same application as the session.

Link a customer

curl -X POST 'https://sandbox.leantech.me/device-intelligence/v1/sessions/customer-links' \
  --header 'Authorization: Bearer <ACCESS_TOKEN>' \
  --header 'Content-Type: application/json' \
  --data '{
    "session_id": "6f0b5f8e-1f0a-4f53-9c11-4d6a0c3f2b7e",
    "customer_id": "4a5e0b1c-2f3d-4e6a-8b7c-9d0e1f2a3b4c"
  }'
{
  "status": "OK",
  "message": "Customer linked to session",
  "timestamp": "2026-10-26T09:14:58.120Z",
  "session_id": "6f0b5f8e-1f0a-4f53-9c11-4d6a0c3f2b7e",
  "customer_id": "4a5e0b1c-2f3d-4e6a-8b7c-9d0e1f2a3b4c",
  "identified_at": "2026-10-26T09:14:58.117Z"
}

Use the same access token as for reading assessments, requested with scope=api.

What linking does

  • Lean assesses the session again. If the session already has an assessment, linking produces a new one that includes the customer-based labels. Its assessment_id changes, and its customer_id is set.
  • A session has one customer. Linking the same customer again is safe and returns the original link, with the original identified_at. Linking a different customer is refused with 409.
  • Every linked session adds to the customer's history, so the customer-based labels become more useful over time.

Labels that need a linked customer

LabelModuleFires when
multiple_customers_same_devicedevice_relationshipsSeveral different customers used this device in the last 30 days
device_new_for_customerdevice_relationshipsThis customer hasn't used this device before
customer_many_devices_7ddevice_relationshipsThis customer used many devices in the last 7 days
ip_many_customers_24hnetwork_analysisMany customers used this IP address in the last 24 hours
impossible_travellocation_analysisThe device is further from the customer's last location than anyone could travel in the time between

While a customer has little history, some of these can't be decided yet. The module then reports INSUFFICIENT_DATA rather than CLEAR, unless another of its labels fired.

Errors

ResponseCause
400session_id or customer_id is missing, or isn't a UUID
404 Session not foundNo session with this id for your application
404 Customer not foundThe customer doesn't exist, or belongs to another application
409 Session already linked to another customerThe session was already linked to a different customer

Did this page help you?