If your app already knows what the customer bought, having a person type the invoice is wasted time. And typed invoices have typos.
An invoice API fixes that. Your code creates the invoice, numbers it, sends it and hears back when it is paid.
Here is how the calls usually fit together, with a real working example, and the mistakes that create duplicate invoices.
What an invoice API does
Most invoicing and payment platforms expose an API with the same building blocks:
- Customers: who the invoice is for, with their email and address.
- Invoices: the document itself, with terms and a due date.
- Line items: what was sold, quantity and price.
- Actions: finalize (lock and number it), send, void.
- Events (webhooks): your server is told when an invoice is paid, fails, or becomes overdue.
The provider handles the PDF, the numbering, the email and often the payment page. Your code just decides what goes on the invoice.
The usual sequence
- Create or look up the customer. Store the provider's customer ID against your own user record so you never create the same customer twice.
- Create a draft invoice for that customer, with the payment terms.
- Add line items to the draft.
- Finalize it. This assigns the invoice number and locks the amounts.
- Send it, by the provider's email or your own.
- Listen for events. When the paid event arrives, mark the order paid in your system.
A working example with Stripe
Stripe's Invoicing API is one widely used example, and its API reference for invoices is public. The calls below use test mode, so nothing is really charged. Replace sk_test_... with your own test secret key and keep it on your server, never in browser code.
1. Create the customer
curl https://api.stripe.com/v1/customers \
-u sk_test_...: \
-d name="Harbor Coffee Roasters LLC" \
-d email="billing@harborcoffee.example"
The response contains the customer ID, which starts with cus_.
2. Create a draft invoice, due in 30 days
curl https://api.stripe.com/v1/invoices \
-u sk_test_...: \
-d customer=cus_123 \
-d collection_method=send_invoice \
-d days_until_due=30
send_invoice means the customer gets an invoice to pay, rather than their card being charged automatically. Keep the invoice ID, which starts with in_.
3. Add a line item to that invoice
curl https://api.stripe.com/v1/invoiceitems \
-u sk_test_...: \
-d customer=cus_123 \
-d invoice=in_123 \
-d amount=120000 \
-d currency=usd \
-d description="Logo refresh"
Amounts are in the smallest currency unit, so 120000 is $1,200.00. Repeat for each line.
4. Finalize, then send
curl -X POST https://api.stripe.com/v1/invoices/in_123/finalize \
-u sk_test_...:
curl -X POST https://api.stripe.com/v1/invoices/in_123/send \
-u sk_test_...:
The customer receives an email with a link to pay. When they do, Stripe sends an invoice.paid event to the webhook endpoint you registered.
Check the provider's current API reference before you build: parameter names and defaults do change between versions.
Mistakes that cause duplicate or wrong invoices
- No idempotency. A network timeout, a retry, and now the customer has two invoices. Send an idempotency key with create requests (Stripe accepts an
Idempotency-Keyheader) and reuse it on retries. - Not storing IDs. Save the provider's customer and invoice IDs against your own records. Matching later by name or email goes wrong.
- Floating point money. Work in whole cents, not 12.99 as a float.
- Tax as an afterthought. Decide where tax is calculated, in your code or by the provider, before your first real invoice.
- Trusting the redirect, not the webhook. A customer closing the payment page early is not a failed payment. Mark invoices paid only from the verified paid event.
- Editing a finalized invoice. You cannot, and should not. Void it or issue a credit note, then create a new one. Our guide to invoice numbering explains why numbers must stay in sequence.
Do you actually need an API?
An API is the right tool when invoices come out of software you run: a marketplace, a SaaS product, a booking system, thousands of orders a month.
If you are a freelancer or a small business sending invoices to clients by hand, you do not need to write code at all. The same result, a numbered invoice, emailed with a Pay button and tracked until it is paid, takes a couple of minutes in invoicing software.
The no-code way: BillingOtter
BillingOtter does the steps above for you, with no code:
- Save your customers once and pick them from a list.
- Add line items; totals and tax work out as you type.
- Each invoice is numbered automatically and emailed with a PDF and a Pay button.
- Clients can pay by card or US bank transfer (on Creator Pro and Team), straight into your own Stripe account.
- Your dashboard shows what is paid, due and overdue.
It is free for 5 invoices a month, no card needed.
Summary
An invoice API call sequence is customer, draft invoice, line items, finalize, send, then a paid event by webhook. Use idempotency keys, store the provider's IDs, and only mark invoices paid from a verified webhook.
Where to start
Easy wins
- Try the example in your provider's test mode first.
- Store the customer and invoice IDs against your own records.
- Add an idempotency key to every create request.
Bigger lifts
- Build a webhook handler that marks orders paid.
- Decide where tax is calculated before you go live.
- Handle voids and credit notes instead of editing finalized invoices.
Frequently asked questions
What is an invoice API? A set of web requests that let your software create, send and track invoices on an invoicing or payments platform.
Do I need a developer to create invoices with an API? Yes, someone has to write and maintain the code. If you only send invoices by hand, invoicing software is simpler.
How do I know when an API invoice is paid? Register a webhook endpoint. The provider calls it with a paid event, and your code updates the order.
Can I create a PDF invoice with an API? Most invoicing APIs generate the PDF for you once the invoice is finalized.
Get paid faster with BillingOtter
Not writing code? BillingOtter does the same steps with no integration: pick a client, add items, send, and get paid into your own Stripe account.
Start free and send your first invoice today. Free Starter covers 5 invoices a month, and you do not need a card.
At BillingOtter, we build invoicing software for US freelancers, contractors and small businesses, so the paperwork takes minutes and the money shows up on time.
Not writing code? BillingOtter creates, numbers, sends and tracks invoices for you. Free for 5 invoices a month.
Try BillingOtter free