Clavem

Move Polar license keys and activations to Clavem without re-issuing them

Polar's API lists every license key with its buyer, limit and expiry, and returns each key's activations on the single-key endpoint. A short script turns that into a Clavem import that keeps the key strings and the activation ids your app stored.

What Polar stores per key

As of November 2026, Polar’s reference for the license key object lists these fields: id, key, display_key, status (granted, revoked or disabled), limit_activations, usage, limit_usage, validations, last_validated_at, expires_at, benefit_id, and a customer with email and name. Keys can have a brandable prefix, such as POLAR_. Each activation has an id, a label, meta and created_at.

Polar Clavem import Note
key key Kept as written, prefix included.
customer.email, customer.name email, name Email is required.
status granted empty Valid.
status revoked or disabled status disabled Both stop working in Polar.
limit_activations activation_limit null becomes -1, unlimited.
expires_at expires_at Empty never expires.
created_at created_at
activation id device instance_id What your app stored as activation_id.
activation label device name
usage, limit_usage, validations not imported No Clavem counterpart.

Step 1: export

The list endpoint is GET https://api.polar.sh/v1/license-keys/ with organization_id, benefit_id, status, page and limit (maximum 100) parameters. It needs a token with the license_keys:read scope. The single-key endpoint adds the activations array. This script walks the pages, asks for each key’s activations and writes licenses.json in the format Clavem’s file import reads. Set POLAR_BENEFIT_ID to export one benefit at a time, because one import file goes to one Clavem product.

// POLAR_TOKEN=... POLAR_BENEFIT_ID=... node export-polar.mjs
import { writeFile } from 'node:fs/promises';
const headers = { Accept: 'application/json', Authorization: `Bearer ${process.env.POLAR_TOKEN}` };

async function get(path, params = {}) {
  const url = new URL(path, 'https://api.polar.sh');
  for (const [k, v] of Object.entries(params)) url.searchParams.set(k, v);
  const res = await fetch(url, { headers });
  if (!res.ok) throw new Error(`${res.status} ${url}`);
  return res.json();
}

const licenses = [];
for (let page = 1; ; page++) {
  const body = await get('/v1/license-keys/', { page, limit: 100, ...(process.env.POLAR_BENEFIT_ID && { benefit_id: process.env.POLAR_BENEFIT_ID }) });
  for (const k of body.items) {
    const { activations = [] } = await get(`/v1/license-keys/${k.id}`);
    licenses.push({
      key: k.key,
      email: k.customer.email,
      name: k.customer.name,
      status: k.status === 'granted' ? '' : 'disabled',
      activation_limit: k.limit_activations ?? -1,
      expires_at: k.expires_at,
      created_at: k.created_at,
      devices: activations.map((a) => ({ instance_id: a.id, name: a.label, created_at: a.created_at })),
    });
  }
  if (page >= body.pagination.max_page) break;
}
await writeFile('licenses.json', JSON.stringify(licenses, null, 2));

Clavem’s parser accepted all 130 records with the devices attached. At one request per key, a few thousand keys take a few thousand requests, so run it once, not in a loop.

Step 2: import, and re-export at cutover

Create a Clavem product for the benefit, choose Import, CSV or JSON file, and check the column preview. Rows are sent in batches of 500, a bad row is reported and the rest import, and a second run only adds what is new. See Import existing licenses. Imported devices keep the activation id, so a validate call with the activation_id your app saved as instance_id succeeds straight away.

Polar lets merchants and customers rotate a key. Its docs say rotation creates a new key string on the same record and that the previous key “stops validating immediately”. Clavem never learns about a rotation. A key rotated after your export will look like a new, unknown key in Clavem, and the old string will still be valid there. Export again just before you cut over, run the import again, and disable the old strings you know were replaced.

Step 3: map the app’s calls

Polar’s customer portal endpoints take key, organization_id, label, activation_id, conditions and increment_usage. Clavem’s take the Lemon Squeezy style fields:

Polar Clavem
POST /v1/customer-portal/license-keys/activate POST /v1/licenses/activate
key license_key
label instance_name
activation_id instance_id
organization_id, conditions, increment_usage none
// Before: Polar
const res = await fetch('https://api.polar.sh/v1/customer-portal/license-keys/validate', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ key, organization_id: ORG_ID, activation_id: activationId }),
});
const k = await res.json();
if (k.status !== 'granted') lock();

// After: Clavem
const res = await fetch('https://clavem.io/v1/licenses/validate', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ license_key: key, instance_id: activationId }),
});
const v = await res.json();
if (!v.valid) lock(v.error);

Polar’s docs tell you to validate organization_id, and to check benefit_id when you sell more than one kind of key. Clavem keeps keys per account and product, and the response meta.product_id and meta.product_name say which product a key belongs to. Check meta.product_id against your own value if the same app accepts several products.

Payments and subscribers

Polar is a merchant of record, so it holds the saved cards. Its documentation index, as of November 2026, lists migration guides into Polar from Stripe and from Lemon Squeezy. It describes no way to move subscribers out, so ask Polar support whether it can help.

Connect your Stripe account to Clavem as in Connecting Stripe and send new buyers through Stripe Checkout, which issues new Clavem keys. For existing subscribers you can ask them to subscribe again, or import their keys with an expires_at and extend it with PATCH /v1/admin/licenses/:id as they renew. Imported keys have no Stripe subscription, so Stripe events never change them, and an empty expires_at means the key never expires. Polar revokes a key automatically when a subscription ends; Clavem will not do that for an imported one.

Leaving a merchant of record also moves tax collection onto you. This is general information, so ask an accountant.

Rollback

The export only reads from Polar. Keep the benefit and its customer portal live while old builds run. Ship the new build with the License API host as a setting, so one release can switch back, and keep licenses.json as an archive. The Licenses screen in Clavem exports every key as CSV.

Questions

Does Polar's license key list include activations?

No. The list response has the key, status, limits, usage, expiry and customer, and the activations array appears on the single-key endpoint, so the export needs one extra request per key.

What about Polar's usage quotas?

Polar keys can carry a usage limit and count usage on each validation. Clavem's License API has no usage counter in its documented fields, so those values are dropped. Move that logic into your app or keep it in Polar.

Can I move Polar subscribers' cards to my own Stripe account?

Polar's docs describe migrating into Polar from Stripe and from Lemon Squeezy. They do not describe a transfer out, so ask Polar support what it can do for your account.

Sources

  1. Polar, license key benefit (checked November 2026)
  2. Polar API, list license keys (checked November 2026)
  3. Polar API, get license key (checked November 2026)
  4. Polar, migrate from Lemon Squeezy (checked November 2026)
  5. Polar documentation index (checked November 2026)