CopperPouch Developer docs
Merchant console

Lemon Squeezy

Move your licence keys from Lemon Squeezy and keep shipped apps working by changing only the licence API base URL. Lemon Squeezy stops processing on 31 March 2027. This works in test mode only.

Export

The export script reads licence keys, activations and order items with your Lemon Squeezy API key and writes a JSON file in the import format. The key is read from the environment and never printed. The file contains live licence keys, so it is created readable only by you.

LEMON_SQUEEZY_API_KEY='<your Lemon Squeezy API key>' \
  pnpm tsx scripts/export-lemon-squeezy-licenses.ts --out licences.json

Pass --store-id to export one Lemon Squeezy store. Each entry in keys looks like this:

{
  "key": "38b1460a-5104-4067-a91d-77b872934d51",
  "license_id": 1,
  "status": "active",
  "activation_limit": 5,
  "expires_at": null,
  "created_at": "2024-03-01T10:00:00.000000Z",
  "customer_email": "buyer@example.com",
  "customer_name": "Buyer One",
  "store_id": 111,
  "customer_id": 222,
  "order_id": 333,
  "order_item_id": 444,
  "product_id": 555,
  "product_name": "Editor",
  "variant_id": 666,
  "variant_name": "Default",
  "instances": [{ "id": "f90ec370-fd83-46a5-8bbd-44a241e78665", "name": "Studio Mac", "created_at": "2024-03-02T09:30:00.000000Z" }]
}

Import

Create and publish a licence policy and a software product first. The mapping assigns each Lemon Squeezy product, or one variant of it, to a CopperPouch product and policy. A variant entry wins over a product entry. A request holds up to 500 keys.

Send dry_run: true to get a report for every row. Nothing is written. Each row is valid, duplicate, invalid with a reason, or unmapped.

API=https://api.copperpouch.com
BODY=$(jq -n --arg store "$STORE_ID" --arg product "$PRODUCT_ID" --arg policy "$POLICY_ID" \
  --slurpfile export licences.json '{
    store_id: $store,
    dry_run: true,
    mapping: { products: [{ ls_product_id: 555, ls_variant_id: null, product_id: $product, policy_id: $policy }] },
    keys: $export[0].keys[0:500]
  }')

curl -sS "$API/v1/licensing/imports/lemon-squeezy" \
  -H "Authorization: Bearer $MERCHANT_TOKEN" -H 'Content-Type: application/json' -d "$BODY"

To apply it, request an import_licenses approval for the request_digest from the dry run, then send the same body with dry_run: false, the approval token and an idempotency key. The approval is bound to the exact keys and mapping. Running it again reports existing keys as duplicate and changes nothing.

# Request approval for data.request_digest from the dry run.
curl -sS "$API/v1/licensing/approvals" \
  -H "Authorization: Bearer $MERCHANT_TOKEN" -H 'Content-Type: application/json' \
  -d "{\"store_id\":\"$STORE_ID\",\"resource_id\":\"$STORE_ID\",\"operation\":\"import_licenses\",\
\"payload\":{\"request_digest\":\"$DIGEST\"}}"

# Send the same body with dry_run set to false.
curl -sS "$API/v1/licensing/imports/lemon-squeezy" \
  -H "Authorization: Bearer $MERCHANT_TOKEN" -H 'Content-Type: application/json' \
  -H "X-Licensing-Approval: $APPROVAL_TOKEN" -H "Idempotency-Key: $(node -p 'crypto.randomUUID()')" \
  -d "$(jq '.dry_run = false' <<<"$BODY")"

Imported keys keep their Lemon Squeezy activation instances, with the same instance IDs and names. Status maps as follows: disabled becomes suspended, expired stays expired, and the activation limit becomes the concurrent device limit.

Compatible API

Change the base URL in your app from https://api.lemonsqueezy.com to https://<copperpouch-api>/compat/lemon-squeezy. The routes are POST /v1/licenses/activate, /validate and /deactivate. They accept form-encoded and JSON bodies and return the Lemon Squeezy response shape. They allow 60 requests a minute from one address.

curl -sS https://<copperpouch-api>/compat/lemon-squeezy/v1/licenses/activate \
  -H 'Accept: application/json' \
  -d license_key='38b1460a-5104-4067-a91d-77b872934d51' \
  -d instance_name='Studio Mac'

Business failures such as This license key has reached the activation limit. return status 400 with activated: false, valid: false or deactivated: false. Unknown keys return 404 and missing fields return 422.

Native keys

Keys issued by CopperPouch use signed device activation, which is stronger than key-only activation. They only work on the compatible API when their licence policy sets allow_key_only_activation to true. The setting defaults to off, and other native keys answer as unknown keys. Numeric IDs in license_key.id and meta are null for native keys.