Customers
A customer is someone you bill. Usually that’s one of YOUR customers — the person, company, or account that’s using your product and that you want to charge or track usage for. When you create a customer in MarginFront, you’re saying “here’s a person I want to track, here’s how to reach them, here’s the ID I use for them in my own system.” Once a customer exists in MarginFront, you can:- Log usage events against them (for usage-based billing)
- Subscribe them to a pricing plan
- Generate invoices for them
- Read their billing history
Create a customer
In plain English: Tell MarginFront about a new customer of yours. Do this right after your own app creates a new user or account. Method & URL:x-api-key header. See Authentication. Publishable keys are rejected on writes with 403.
Required fields:
name(string) — The customer’s company name or full name. Shows up on invoices, so make it readable.
externalId(string) — Your internal ID for this customer. Pick something you already use in your own system. This is how you’ll reference the customer in other API calls (like usage events) without having to remember MarginFront’s internal UUID.email(string) — The billing email. Where invoices get sent.
phone(string) — Customer phone numberaddressLine1,addressLine2,city,state,zipCode,country(string) — Mailing address, used on invoicestimezone(string, default"UTC") — Customer’s timezone, used for billing period calculationsstatus("active"|"inactive"|"suspended", default"active")billingContactName(string) — If the billing contact is different from the main contactbillingContactEmail(string) — Same, for emailnetTerms(number, default30) — Payment terms in daysinvoiceEmailRecipients(array of strings) — Additional email addresses to CC on invoicesmetadata(object) — Any custom key/value pairs you want to attach. MarginFront stores and returns them but doesn’t interpret them.
201 Created):
400 Bad Request— You’re missing thenamefield, or one of your fields has the wrong type (e.g., an email that isn’t a valid email). The response body will tell you exactly which field is wrong.409 Conflict— A customer with thatexternalIdalready exists in this org. Either pick a differentexternalId, or update the existing customer instead.401 Unauthorized— Your API key is missing or wrong.403 Forbidden— You used a publishable key (mf_pk_*) on a write. Use a secret key (mf_sk_*) instead.
Heads up: If you log a usage event for an externalId that MarginFront has never seen before, MarginFront will auto-create a minimal customer record for you. This is convenient but means you miss the chance to set the name/email/etc. Creating the customer explicitly first gives you much richer data.
Read a customer
Method & URL:404 Not Found— No customer with that ID exists in this org.
List customers
Method & URL:Update a customer
Method & URL:200 OK): The updated customer object.
Common errors:
404 Not Found— Customer doesn’t exist.409 Conflict— You tried to changeexternalIdto one that another customer in this org already has.403 Forbidden— You used a publishable key on a write.
Delete a customer
Method & URL:404 Not Found— Customer doesn’t exist.409 Conflict— Customer still has active subscriptions. Cancel or delete those first.403 Forbidden— You used a publishable key on a write.
Using the Node SDK
If you’re using the published@marginfront/sdk npm package, you never type these URLs yourself. Instead:

