# Bring your existing clients across (/docs/embed/existing-clients)

Clients who signed up before today have no website yet. Run this once before you launch: for each of them it does what [sign-up](/docs/embed/create-website) does, then sets them to paid or trial like your billing webhook ([trial](/docs/embed/start-trial) or [paid](/docs/embed/switch-to-paid)).

It is **safe to run again**: clients that already have a `websiteId` are skipped, and the id is saved before the next call, so a re-run only retries the failures.

```js title="scripts/happierleads-migrate.js"
const API = process.env.HL_API_BASE ?? 'https://rest-admin.happierleads.com';
const DRY_RUN = process.argv.includes('--dry-run');

async function hl(method, path, body) {
  const r = await fetch(`${API}${path}?privateKey=${process.env.HL_MASTER_KEY}`, {
    method,
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(body),
  });
  if (!r.ok) throw new Error(`${method} ${path} → ${r.status} ${await r.text()}`);
  return r.json();
}

const companies = await db.companies.find({ happierleadsWebsiteId: null }); // your own query
let ok = 0, failed = 0;
for (const c of companies) {
  if (DRY_RUN) { console.log('would create', c.id, c.name); continue; }
  try {
    const { websiteId } = await hl('POST', '/admin/websites', { name: c.name, domain: c.domain || '' });
    await db.companies.update(c.id, { happierleadsWebsiteId: websiteId }); // save first, then limits
    await hl('PUT', `/admin/websites/set-limits/${websiteId}`, { credits: c.plan.leads, emailAccounts: 2 });
    await hl('PUT', `/admin/websites/toggle-limits/${websiteId}`, c.isPaying
      ? { trialEnabled: false, activeWebsite: true, enableWebsiteLimits: true, refreshOnDate: c.renewsAt }
      : { trialEnabled: true, trialExpireDate: c.trialEndsAt, enableWebsiteLimits: true });
    ok += 1;
    console.log('ok', c.id, websiteId);
  } catch (e) {
    failed += 1;
    console.error('FAILED', c.id, e.message); // run again to retry
  }
  await new Promise((r) => setTimeout(r, 300)); // about 3 calls a second
}
console.log({ total: companies.length, ok, failed });
```

1. Run it with `--dry-run` and check the list.
2. Run it on staging, open a few clients' screens.
3. Run it on production and compare the summary with your client count.

**Next:** [security checklist](/docs/embed/security).
