Skip to main content

Migrate from Lemon Squeezy (for coding agents)

Written 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_KEY on 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 0600 and 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​

ValueEnvironment variableUsed for
API base URLLICENSR_API_BASEEvery call. Production is https://api.licensr.app.
Product slugaskplugin_slug on license calls.
Server keyLICENSR_SERVER_KEYThe import. Server only. One per product.
Client keyLICENSR_CLIENT_KEYLicense checks inside the product. Safe to ship.
Plan id for each variantaskplan_id on each imported row. GET /v1/seller/plans lists them.
Lemon Squeezy API keyLEMON_SQUEEZY_API_KEYExport 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.

ReadFor
GET /v1/license-keysOne 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-itemsA key row does not name its variant. Match order_item_id to an order item and read its variant_id.
GET /v1/subscriptionsMatch 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/variantsThe 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.
  • status of inactive is a paid key nobody has activated yet. Import it. disabled and expired are skipped and not stored. Omit status for an active key.
  • Send max_seats from the key's activation limit. Send null when that limit is unlimited. Omit it only to inherit the plan.
  • expires_at is optional. Use the key's expiry. When a subscription key has none, use ends_at if the subscription is ending, otherwise renews_at. A date in the past is skipped as an expired key.
  • Send external_meta with numeric store_id, product_id, variant_id, and license_key_id, plus order_id, order_item_id, customer_id, and subscription_id when you have them. Apps compare these.
  • Send customer_name when you have it. It is returned only if the seller turns on full email for the product.
  • dry_run: true writes nothing. cap.remaining is the room left after the batch you sent, so 0 can mean the batch just fits. The signal to stop is a row with error: "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 returns cap.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_run false or omitted) does not email buyers and does not send a webhook.
  • The same external_id again never creates a second license. It returns already_imported, or updated when 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 an error code. The other rows in the batch are still imported. The codes are listed in the migration guide. Report failed rows to the seller by external_id, never by key.
  • The response does not repeat an imported key. It returns key only when you omitted key and 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.

Reference​