# Migrate from Lemon Squeezy (/docs/license-keys/migrate-from-lemon-squeezy)

Importing keys does not migrate subscriptions or payments. Use a `generated` service and switch your app to the [Comecero License key API](/docs/license-keys/license-key-api).

Use Node 22+ and `jq`. Keep files private: they contain full keys. Stop source device changes before the final export.

## 1. Download and export [#1-download-and-export]

```bash
curl -fLO https://docs.comecero.com/downloads/export-lemon-squeezy.mjs
curl -fLO https://docs.comecero.com/downloads/convert-lemon-squeezy.mjs

LS_API_KEY='...' LS_STORE_ID='10' LS_MODE='live' \
  node export-lemon-squeezy.mjs > lemon-squeezy.json
```

The API key sets the mode; set `LS_MODE` to match. The exporter reads every page and checks device counts. If counts differ, stop changes and export again.

The exporter keeps each UUID `attributes.identifier`, which installed apps save, instead of the numeric JSON:API `id`.

## 2. Match customers and products [#2-match-customers-and-products]

Create Comecero customers and digital or service products in the target mode. Match source IDs in these files; check email matches.

```json title="customers-map.json"
{ "15": "customer_test" }
```

Products use `product_id:variant_id`; leave the suffix empty without a variant.

```json title="products-map.json"
{ "30:40": "widget-pro.test" }
```

```bash
node convert-lemon-squeezy.mjs \
  --input lemon-squeezy.json \
  --customers customers-map.json \
  --products products-map.json \
  --rows-per-batch 20 \
  --output batches
```

Missing matches or devices stop conversion. Expired and revoked keys keep devices. Batch files are not overwritten.

| Source value | Comecero value |
| --- | --- |
| `active` or `inactive` | `status: active` |
| `expired` | Keeps past expiry; validation returns `EXPIRED` |
| `disabled` status or `disabled: 1` or true | `status: revoked`, `revoked_reason: merchant` |
| Limit `0` or null | No device limit |
| Device `identifier`, `name`, `created_at` | `instance_id`, `name`, `activated_at` |

| Limit | Maximum |
| --- | --- |
| Dashboard source file | 20 MiB                       |
| Keys per batch | 20 |
| Devices per key | 90; contact support for more |
| Devices per batch | 500 |
| JSON body | 1 MiB |
| Requests per account | Five per minute across modes |

## 3. Check and import each batch [#3-check-and-import-each-batch]

Set your secret or trusted token and service ID. The token sets the mode. Test with made-up keys or another account: one key cannot exist in both modes.

```bash
CORE='https://api.comecero.com'
TOKEN='...'
SERVICE='...'
jq '.dry_run = true' batches/001.json > preview.json

curl --fail-with-body "$CORE/api/v1/license_services/$SERVICE/imports" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: ls-preview-001" \
  --data-binary @preview.json
```

Review every row, then import:

```bash
curl --fail-with-body "$CORE/api/v1/license_services/$SERVICE/imports" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: ls-import-001" \
  --data-binary @batches/001.json
```

Use a new request key per batch and dry run. Follow `Retry-After`. If you receive an error with `error.meta.import_id`, read that receipt before retrying. A timeout may give no reply and no receipt ID. In that case, deliberately resend the **same body and same Idempotency-Key**, for example rerun the exact curl command above with the same file. The request replays the saved receipt or continues unfinished rows. Never retry in the background. After a dashboard reload, choose the same file and matches; the rebuilt body must match the saved digest.

Correct failed rows with a new request key. Change successful imports through [Update a license](/api/licenses/update-license); a new import key does not bypass source conflicts. Check every row, including its flat `error.message`, and keep receipt IDs for later batches.

Read a known receipt and its imported license:

```bash
IMPORT_ID='...'
LICENSE_ID='...'
curl --fail-with-body "$CORE/api/v1/license_services/$SERVICE/imports/$IMPORT_ID" \
  -H "Authorization: Bearer $TOKEN"

curl --fail-with-body "$CORE/api/v1/licenses/$LICENSE_ID" \
  -H "Authorization: Bearer $TOKEN"
```

## 4. Switch your app [#4-switch-your-app]

Wait for `active_in_apollo: true`. Switch your app's host, `account_id` and request handling. Validate saved UUIDs before new activations. Imported devices have `fingerprint: null`.

Test a full key: `block` refuses new devices; `rotate` replaces the oldest and keeps the count. Removed devices return `INSTANCE_DEACTIVATED`. Deactivation lowers the count once. Re-import must not restore devices.

See [Import existing keys](/docs/license-keys/import-licenses) for access, CSV and updates.
