LemuAIDocs

Guides · 4 min read

Embedding in Your ERP

Show a customer's tickets, a request form or one ticket inside your own app with embed tokens and the <lemu-tickets> element

Open in ChatGPTOpen in ClaudeMarkdown

The <lemu-tickets> element puts LemuTickets screens inside your ERP, customer portal or website, without you building them. It shows one customer (a requester) their own tickets, lets them raise a new one, and lets them reply. Your agents see and answer everything in LemuTickets as usual.

It works in two steps:

  1. Your server asks the API for a short-lived embed token for the signed-in customer.
  2. Your page loads the script and adds a <lemu-tickets> element with that token.

Never put an API key in a web page. An embed token is safe to put in the page: it only works for one requester, only on the embed screens, only from the sites you list, and only for a short time.

1. Get an embed token on your server#

POST/v1/embed/tokens

Call this with an API key or OAuth token that has the tickets.write scope.

FieldTypeRequiredDescription
requester_idstring (UUID)One of the threeThe LemuTickets requester id.
requester_external_idstringOne of the threeYour own id for the customer, as set with Upsert a requester by external ID.
requesterobjectOne of the threeemail, phone and name. Finds the requester by email or phone, or creates one. Needs an email or a phone.
scopestringNoWhat the token allows. list (default), create or ticket. See below.
ticket_keystringFor ticketThe ticket to show, for example SUP-1042. It must belong to this requester.
projectstringNoProject key or id for tickets the customer creates. Without it, new tickets go to your first open service desk project.
ttl_minutesintegerNoHow long the token lasts, 1 to 1440 minutes. Default 60.
allowed_originsarray of stringsNoThe sites allowed to use the token, as origins like https://erp.example.com (no path). Strongly recommended. Empty means any site.
ScopeThe customer can
listSee all their tickets, open any of them, reply, and raise new tickets
createRaise new tickets only
ticketOpen and reply on the one ticket in ticket_key

Example request:

cURL
curl -X POST https://api.tickets.lemuai.com/v1/embed/tokens \
  -H "Authorization: Bearer ltk_live_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "requester_external_id": "CUST-20931",
    "scope": "list",
    "project": "SUP",
    "ttl_minutes": 60,
    "allowed_origins": ["https://erp.example.com"]
  }'

201

JSON
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "expires_at": "2026-11-25T10:12:40.512000+00:00",
  "scope": "list",
  "requester_id": "8b4d6f2a-0c1e-4a3b-9d5f-7e6a8c0b2d4f",
  "ticket_key": null,
  "allowed_origins": ["https://erp.example.com"],
  "script_url": "https://api.tickets.lemuai.com/v1/public/embed.js",
  "snippet": "<script src=\"https://api.tickets.lemuai.com/v1/public/embed.js\" async></script>\n<lemu-tickets token=\"eyJhbGciOi...\" view=\"list\"></lemu-tickets>"
}

snippet is ready-made HTML for this token.

StatuscodeWhen
422missing_requesterNone of requester_id, requester_external_id or requester (with an email or phone) was sent
422invalid_requesterNo requester with that id or external id
422requester_unavailableThe requester's self-service access is turned off, or their data was anonymised
422missing_ticket_keyscope is ticket but there is no ticket_key
422ticket_not_requestersThe ticket belongs to another requester
422invalid_originAn entry in allowed_origins is not an origin like https://erp.example.com

2. Add the element to your page#

Load the script once per page, then add an element for each screen:

HTML
<script src="https://api.tickets.lemuai.com/v1/public/embed.js" async></script>
 
<!-- The customer's tickets (token with scope "list") -->
<lemu-tickets token="TOKEN_FROM_YOUR_SERVER" view="list"></lemu-tickets>
 
<!-- A "raise a request" form (token with scope "create") -->
<lemu-tickets token="TOKEN_FROM_YOUR_SERVER" view="create"></lemu-tickets>
 
<!-- One ticket with its replies (token with scope "ticket") -->
<lemu-tickets token="TOKEN_FROM_YOUR_SERVER" view="ticket" ticket="SUP-1042"></lemu-tickets>
AttributeDescription
tokenThe embed token from step 1. Required.
viewlist (default), create or ticket. It should match the token's scope.
ticketThe ticket key, for view="ticket".
statusOptional, for view="list". open shows every ticket that is not done. Otherwise a comma-separated list of status categories, for example waiting or new,open.

The customer only ever sees their own tickets and public replies. Internal notes stay hidden. Tickets they raise have the source portal.

Refreshing tokens#

Tokens expire (after 60 minutes by default). Ask your server for a new token each time the page loads. If the page stays open a long time, fetch a new token before expires_at and set it on the element:

JavaScript
document.querySelector("lemu-tickets").setAttribute("token", newToken);

Changing an attribute redraws the element.

Events#

The element sends DOM events you can listen to, for example to refresh your own screen:

Eventevent.detail
lemu:ticket-createdThe new ticket: id, key, title, status, status_category, priority, type, created_at and more
lemu:reply-sentThe reply: id, ticket_key, body_text, created_at
lemu:error{ code, message }, for example embed_token_expired when the token ran out
JavaScript
document.addEventListener("lemu:error", (e) => {
  if (e.detail.code === "embed_token_expired") refreshToken();
});

Styling#

The element draws inside its own shadow DOM, so your page's styles do not leak into it. Set these CSS variables on the element to match your brand:

CSS
lemu-tickets {
  --accent: #0b6e4f;
  --accent-hover: #095c42;
  --ink: #1d1d1f;
  --slate: #6b6b73;
  --mist: #f4f4f5;
  --line: #ececee;
  --radius: 12px;
}

When something goes wrong#

What you seeWhy
"Missing token."The token attribute is empty.
network_error ("Could not reach the support service.")Often the page's origin is not in the token's allowed_origins, so the browser blocks the response. Origins must match exactly, including https and any port.
embed_token_expiredThe token ran out. Get a new one from your server.
embed_scopeThe token's scope does not allow this view, for example a create token used with view="list".

Was this page helpful?