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_idchanges, and itscustomer_idis 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 with409. - 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
| Label | Module | Fires when |
|---|---|---|
multiple_customers_same_device | device_relationships | Several different customers used this device in the last 30 days |
device_new_for_customer | device_relationships | This customer hasn't used this device before |
customer_many_devices_7d | device_relationships | This customer used many devices in the last 7 days |
ip_many_customers_24h | network_analysis | Many customers used this IP address in the last 24 hours |
impossible_travel | location_analysis | The 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
| Response | Cause |
|---|---|
400 | session_id or customer_id is missing, or isn't a UUID |
404 Session not found | No session with this id for your application |
404 Customer not found | The customer doesn't exist, or belongs to another application |
409 Session already linked to another customer | The session was already linked to a different customer |
Updated about 21 hours ago
