Create Customer Records Automatically on Purchase
Clifford2 min read
webhookscustomer managementautomationcrmkeymint
Every time you generate a license key — from the dashboard, via API, or from a Stripe checkout — you need that customer in your own database. Keymint's license.created webhook makes this automatic.
How It Works
- Your backend creates a license via
admin.createKey()orPOST /key - Keymint emits
license.createdwith the license details - Your handler receives it, verifies the signature
- Your handler upserts the customer and license into your database
- Optionally sends a welcome email
Events to Sync
| Event | What to do |
|---|---|
customer.created | Insert customer row |
customer.updated | Update name, email |
customer.disabled / customer.enabled | Toggle active status |
license.created | Insert license row, send welcome email |
license.updated | Sync expiry, maxActivations |
license.disabled / license.enabled | Toggle status |
device.activated | Increment activation count in UI |
device.deactivated | Decrement activation count |
The Handler (Essentials)
typescript
const event = JSON.parse(payload);
switch (event.type) {
case 'customer.created': {
const c = event.data?.customer || {};
await db.customer.upsert({
where: { keymintId: event.resource_id },
create: { name: c.name, email: c.email, active: true },
update: { name: c.name, email: c.email },
});
break;
}
case 'license.created': {
const lic = event.data?.license || {};
await db.license.upsert({
where: { keymintId: event.resource_id },
create: { productId: lic.productId, customerId: lic.customerId, status: 'active' },
update: { status: 'active' },
});
// Send welcome email with license details
if (lic.customerEmail) {
await sendWelcomeEmail(lic.customerEmail, lic.productId);
}
break;
}
}Idempotency
Keymint may deliver webhooks more than once. Store event.id (a UUID) and skip duplicates:
typescript
const exists = await db.webhookEvents.findUnique({
where: { keymintEventId: event.id },
});
if (exists) return Response.json({ received: true });Going Further
- Sync to a CRM: push to HubSpot, Salesforce, or Pipedrive instead of your database
- Enrich with Stripe data: look up the Stripe customer by email and pull MRR, plan tier
- Trigger a welcome sequence: combine with a transactional email provider (Resend, Postmark)
Full webhook event catalog: keymint.dev/docs/topics/webhooks