Self-service, shop-scoped tokens for calling the Legion API from your own backend — starting with enabling and disabling user accounts.
1. Generate
A shop Owner or Admin creates a token in the admin dashboard under Settings → API Tokens. It is revealed exactly once.
2. Call the API
Your backend sends the token as a bearer token. Every request is scoped to your own shop — no other tenant is reachable.
3. Revoke anytime
Revoke a token from the same settings page. It stops working on the very next request.
API tokens let your backend call the Legion API directly — no widgets, no user session — to automate account administration for your own tenant. The first supported use case is enabling and disabling user accounts (the active flag), for example after verifying a customer in your ERP or CRM.
Tokens are generated by you, from the Legion admin dashboard. No contact with Legion support is required.
Any dashboard user with the Owner or Admin role on your shop. Tokens are always scoped to the shop they were generated in: a token can only read or modify users that belong to your own tenant. Requests against any other tenant's data return 404 Not Found.
ERP customer sync) and pick an expiration: 30, 90, or 365 days.The token is shown exactly once, in the "API Token Created" dialog. Copy it and store it in your secret manager immediately — Legion does not store the token and cannot show it again. If you lose it, revoke it and generate a new one.
Send the token as a standard bearer token in the Authorization header:
Authorization: Bearer <YOUR_API_TOKEN>
PATCH /api/user/profile flips a user's active flag. Identify the target user with exactly one of id, email, phone, or username. Pass active: true or active: false explicitly, or omit active to toggle the current value.
1# Disable a user by email
2curl -X PATCH "https://your-legion-domain.com/api/user/profile" \
3 -H "Authorization: Bearer $LEGION_API_TOKEN" \
4 -H "Content-Type: application/json" \
5 -d '{ "data": { "email": "[email protected]", "active": false } }'1# Re-enable a user by id
2curl -X PATCH "https://your-legion-domain.com/api/user/profile" \
3 -H "Authorization: Bearer $LEGION_API_TOKEN" \
4 -H "Content-Type: application/json" \
5 -d '{ "data": { "id": "9a1f...c3", "active": true } }'A successful response returns the user's new state:
1{
2 "id": "9a1f...c3",
3 "active": true,
4 "email": "[email protected]",
5 "phone": "+15551234567",
6 "username": "customer1"
7}Node.js example:
1const res = await fetch("https://your-legion-domain.com/api/user/profile", {
2 method: "PATCH",
3 headers: {
4 Authorization: `Bearer ${process.env.LEGION_API_TOKEN}`,
5 "Content-Type": "application/json",
6 },
7 body: JSON.stringify({
8 data: { email: "[email protected]", active: false },
9 }),
10});
11
12if (!res.ok) {
13 throw new Error(`Legion API error: ${res.status}`);
14}
15const user = await res.json();
16console.log(`User ${user.id} active: ${user.active}`);While a user is disabled, the Legion UI informs them that their access is pending approval. Accounts can also be re-activated automatically by your ERP sync, if configured.
GET /api/admin/users/exists looks up a customer by exactly one of email or phone within your shop.
curl "https://your-legion-domain.com/api/admin/users/[email protected]" \
-H "Authorization: Bearer $LEGION_API_TOKEN"1{
2 "exists": true,
3 "user": { "id": "9a1f...c3", "email": "[email protected]", "phone": null },
4 "matchCount": 1
5}When no customer matches, the response is { "exists": false, "user": null, "matchCount": 0 }.
POST /api/admin/users creates a customer in your shop. At least one of email or phone is required; firstName and lastName are optional. The call is idempotent — if a customer with the same email or phone already exists, they are returned with created: false (status 200) instead of a duplicate being created (status 201).
1curl -X POST "https://your-legion-domain.com/api/admin/users" \
2 -H "Authorization: Bearer $LEGION_API_TOKEN" \
3 -H "Content-Type: application/json" \
4 -d '{ "email": "[email protected]", "firstName": "Ada", "lastName": "Lovelace" }'{ "created": true, "user": { "id": "9a1f...c3" } }Phone numbers are normalized to E.164 before matching or storing, so 555-123-4567 and +15551234567 refer to the same customer.
Response codes for the customer endpoints:
| Status | Meaning |
|---|---|
200 | Lookup succeeded (exists may be true or false), or the customer already existed (created: false). |
201 | The customer was created (created: true). |
400 | Missing/ambiguous identifier or invalid phone number. |
401 | Missing, malformed, expired, or revoked token. |
409 | The email and phone belong to two different existing customers. |
PATCH /api/user/profile | Status | Meaning |
|---|---|
200 | The active flag was updated; the response body contains the new state. |
400 | Missing or ambiguous identifier, or active was not a boolean. |
401 | Missing or malformed Authorization header, or the token has expired. |
403 | The token was revoked, or is not valid for this operation. |
404 | No user matched the identifier within your shop. |
Tokens can be revoked at any time from Settings → API Tokens — click Revoke next to the token. Revocation takes effect immediately: the next request made with that token is rejected with 403. Revoke a token right away if it may have been exposed, and generate a replacement.
The interactive API reference at /api/docs lists every endpoint available to your integration, with request and response schemas. Endpoints tagged with bearer authentication accept either an API token (shop-scoped, admin operations) or an end-user token (SSO / widget flows), as noted per endpoint.
Related Documentation
SSO Authentication — short-lived, per-user tokens for widgets and end-user API calls. Read the SSO guide →
API Reference — interactive documentation for every available endpoint. Open the API reference →
Integration Guide — widgets, webhooks, and SDKs. Back to the integration guide →