Create a website when a client signs up
In your sign-up code: one website per client, its id saved on your customer.
Every client gets one website. Create it in your sign-up code, right after you create the client's company in your own database, with your master key (HL_MASTER_KEY, sent as ?privateKey=).
1. Create the website
POST /admin/websites with the client's name and domain. The domain may be empty: the install screen asks the client for it. The answer is the new website's id.
/admin/websitescurl -X POST "https://rest-admin.happierleads.com/admin/websites?privateKey=YOUR_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "Acme Ltd", "domain": "acme.example"}'2. Save the websiteId on your client
Do this before any other call
Store the websiteId on your own customer record (for example company.happierleadsWebsiteId). It is the only link between your client and their website: credits, trial, paid, cancel and every screen you open later need it. Lose it and that client cannot open their screens.
// after POST /admin/websites, before anything else
await db.companies.update(company.id, { happierleadsWebsiteId: websiteId });3. Then give it credits
In the same sign-up request, right after saving the id: start a trial, or switch it to paid if the client paid at sign-up.
If our API is down at sign-up
Let the sign-up succeed anyway: flag the company (for example happierleadsPending) and retry from a background job. Never create a second website for a company that already has a websiteId.