Migrate from Lemon Squeezy (for coding agents)
Follow this page exactly. Ask the seller for any value you do not have. Never invent a key, and never ask the seller to paste a license key or an API key into the chat. Read secrets from environment variables.
Rules
- Never paste license keys or API keys into the chat, logs, or a repository.
- The Licensr server key is
LICENSR_SERVER_KEYon the seller's server. Never put it in code that ships to customers. - The Lemon Squeezy API key is
LEMON_SQUEEZY_API_KEY. It can change the seller's store. Do not send it to Licensr. Delete any file you write that contains it. - If you write an export file, create it with mode
0600and delete it when the import finishes. - Run a dry run before importing. Stop if any row comes back with
plan_cap_exceeded. - A server key belongs to one product. For a store with several products, ask for one server key per product and send each product's keys with its own server key.
- Do not log license keys.
Values to ask the seller for
| Value | Environment variable | Used for |
|---|---|---|
| API base URL | LICENSR_API_BASE | Every call. Production is https://api.licensr.app. |
| Product slug | ask | plugin_slug on license calls. |
| Server key | LICENSR_SERVER_KEY | The import. Server only. One per product. |
| Client key | LICENSR_CLIENT_KEY | License checks inside the product. Safe to ship. |
| Plan id for each variant | ask | plan_id on each imported row. GET /v1/seller/plans lists them. |
| Lemon Squeezy API key | LEMON_SQUEEZY_API_KEY | Export only, on the seller's machine. |
1. Import existing keys
Lemon Squeezy license keys are UUIDs. Send that string as key and the numeric license id as external_id. Customers keep using that key.
The product and its plans must already exist in Licensr. The Seller API does not create them. If GET /v1/seller/plans returns no plan for a variant, stop and ask the seller to create it in the dashboard, or to run the dashboard importer.
Read the Lemon Squeezy store
Call https://api.lemonsqueezy.com with Authorization: Bearer $LEMON_SQUEEZY_API_KEY and Accept: application/vnd.api+json. Every list is paged: add page[size]=100 and follow links.next until it is absent.
| Read | For |
|---|---|
GET /v1/license-keys | One row per key: key, status, user_email, user_name, activation_limit, expires_at, store_id, customer_id, order_id, order_item_id, product_id, test_mode. The row's id is external_id. |
GET /v1/order-items | A key row does not name its variant. Match order_item_id to an order item and read its variant_id. |
GET /v1/subscriptions | Match on order_item_id, then order_id. Use ends_at, otherwise renews_at, as the key's expiry when the key has none. |
GET /v1/variants | The variant's name, to match a plan. |
Use a live-mode API key. A test-mode key reads test-mode data only. Leave out any row with test_mode true.
Or write a file for the dashboard. If the seller prefers to import in the dashboard without giving Licensr the API key, write a CSV (mode 0600) with this header and one row per key, and tell the seller to choose it under "Use a file instead" in the importer:
product_name,product_id,variant_name,variant_id,price_cents,currency,interval,email,license_key,license_id,status,seats,expires_at,store_id,customer_name,trial
interval is month, year, or empty for a one-time price. seats is empty for unlimited. expires_at is ISO 8601 in UTC. Do not print the file.
Send the rows
GET /v1/seller/plans with Authorization: Bearer $LICENSR_SERVER_KEY returns this product's plans.
Then:
curl -s -X POST "$LICENSR_API_BASE/v1/seller/licenses/import" \
-H "Authorization: Bearer $LICENSR_SERVER_KEY" \
-H "Content-Type: application/json" \
-d '{"dry_run": true, "items": [{"customer_email": "buyer@example.com", "plan_id": "<plan-id>", "external_id": "<lemon-squeezy-license-id>", "key": "<the-customers-key>", "status": "active"}]}'
- Up to 100 items. Body at most 256 KB, with
Content-Length. statusofinactiveis a paid key nobody has activated yet. Import it.disabledandexpiredare skipped and not stored. Omitstatusfor an active key.- Send
max_seatsfrom the key's activation limit. Sendnullwhen that limit is unlimited. Omit it only to inherit the plan. expires_atis optional. Use the key's expiry. When a subscription key has none, useends_atif the subscription is ending, otherwiserenews_at. A date in the past is skipped as an expired key.- Send
external_metawith numericstore_id,product_id,variant_id, andlicense_key_id, plusorder_id,order_item_id,customer_id, andsubscription_idwhen you have them. Apps compare these. - Send
customer_namewhen you have it. It is returned only if the seller turns on full email for the product. dry_run: truewrites nothing.cap.remainingis the room left after the batch you sent, so0can mean the batch just fits. The signal to stop is a row witherror: "plan_cap_exceeded": tell the seller to upgrade their Licensr plan. When the first import goes over a Free or paid plan but fits the Agency limits (5,000 licenses), Licensr opens a one-time 7-day trial with those limits and returnscap.trial_ends_at(a dry run reports the date it would end without opening it). Tell the seller to choose a plan before that date: after it, new licenses stop at the plan's limit, and the imported keys keep working for 14 more days.- A real import (
dry_runfalse or omitted) does not email buyers and does not send a webhook. - The same
external_idagain never creates a second license. It returnsalready_imported, orupdatedwhen the expiry, seat limit, or status you sent differs from what is stored. So the script is safe to run again, and running it again after a renewal or a refund at Lemon Squeezy brings Licensr up to date. - A row that fails comes back with
outcome: "error"and anerrorcode. The other rows in the batch are still imported. The codes are listed in the migration guide. Report failed rows to the seller byexternal_id, never by key. - The response does not repeat an imported key. It returns
keyonly when you omittedkeyand Licensr minted one. error: "key_not_accepted"means that key was not stored. Do not retry it with a different id.- 10 requests a minute per server key. On
429, wait 15 seconds and send the same batch again.
Map each Lemon Squeezy variant to the plan id the seller confirms. Do not guess prices.
2. Switch the app
Prefer the Licensr SDK for the project's language (SDKs). The customer's key is whatever they already enter, including an imported UUID.
import {LicensrClient} from '@licensr/sdk';
const client = new LicensrClient({
apiKey: process.env.LICENSR_CLIENT_KEY!,
pluginSlug: '<product-slug>',
});
const activation = await client.activate({
licenseKey: userEnteredKey,
activationType: 'seat',
identifier: stableMachineId,
});
const result = await client.validate({licenseKey: userEnteredKey});
Unlock only when result.valid is true. An unknown key is 200 with valid: false.
If the seller turns on Lemon Squeezy compatibility for the product (the dashboard importer does this for the products it creates), the smallest change is the address: replace https://api.lemonsqueezy.com/v1/licenses/ with https://api.licensr.app/v1/lemonsqueezy/<store-slug>/licenses/ (ask the seller for the store slug, the part after /buy/ in their buy page address) and leave the activate, validate, and deactivate calls as they are. The response shape, status codes, and error text match Lemon Squeezy. That is a bridge. New code should call the SDK.
Whichever you choose, check the code that reads the key from the customer. New buyers get a key that starts with lic_, not a UUID. If the project rejects anything that is not a UUID before calling the API, let it accept both.
Tell the seller to release this build early. Installed versions keep calling Lemon Squeezy until the customer updates, and Lemon Squeezy stops answering on 31 March 2027.
Do not import Lemon Squeezy activations. The next check of an installed app takes a seat. The compatibility URLs return the same instance id the app sent. A daily, weekly, or every-N variant has no matching Licensr price: ask the seller to pick monthly or yearly for new sales. Do not copy a trial onto the plan that holds imported keys.
3. New sales and subscribers
Point new buyers at https://licensr.app/buy/<store-slug>. Subscriptions are the seller's decision, made in the dashboard under Products → Imported from Lemon Squeezy: Lemon Squeezy's own migration tool can move card subscriptions to the seller's Stripe account (then the seller removes the end date from those keys), or the customer subscribes again on Licensr and keeps the same key. Do not write code for either; point the seller to the Subscriptions section of the migration guide. One-time buyers keep their imported key and do not pay again unless the seller says so.