Developer Documentation

API Tokens

Self-service, shop-scoped tokens for calling the Legion API from your own backend — starting with enabling and disabling user accounts.

Self-Service
Shop-Scoped
Revocable

API Tokens (Self-Service)

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.

Who can generate tokens

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.

Generating a token

  1. Log in to the Legion admin dashboard.
  2. Go to Settings → API Tokens.
  3. Click Generate Token.
  4. Give the token a descriptive name (e.g. ERP customer sync) and pick an expiration: 30, 90, or 365 days.
  5. Click Generate.

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.

Using a token

Send the token as a standard bearer token in the Authorization header:

Authorization: Bearer <YOUR_API_TOKEN>

Enable or disable a user account

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.

Check whether a customer exists

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 }.

Create a customer

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:

StatusMeaning
200Lookup succeeded (exists may be true or false), or the customer already existed (created: false).
201The customer was created (created: true).
400Missing/ambiguous identifier or invalid phone number.
401Missing, malformed, expired, or revoked token.
409The email and phone belong to two different existing customers.

Response codes for PATCH /api/user/profile

StatusMeaning
200The active flag was updated; the response body contains the new state.
400Missing or ambiguous identifier, or active was not a boolean.
401Missing or malformed Authorization header, or the token has expired.
403The token was revoked, or is not valid for this operation.
404No user matched the identifier within your shop.

Revoking a token

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.

Security best practices

  • Server-side only. API tokens carry admin-level privileges for your shop. Never embed them in a browser, mobile app, or widget. For user-facing widgets, use SSO authentication instead — those tokens are short-lived and scoped to a single end user.
  • Store tokens in a secret manager (environment variables, Vault, etc.), never in source control.
  • One token per integration. Give each system (ERP sync, support tooling, etc.) its own named token so you can revoke one without breaking the others.
  • Prefer shorter expirations and rotate: generate a new token, deploy it, then revoke the old one.

Full API reference

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 →