Skip to main content
This page covers the API. To create the same invoice by hand, see Invoices. For the charges you bill, see Charges.
POST /v1/invoices bills a customer once for one or more charges. There is no subscription and nothing recurs. It needs the invoices:write scope and an Idempotency-Key. It returns the invoice with status 201. Saasybill applies the same rules as the New Invoice form and sends the invoice to Xero before it answers.
This is never a subscription invoice and it is not recurring revenue. Each line has the revenue type one_time. Saasybill records it in the one-time charge account chosen for the organisation in Xero.

Request fields

A charge allows an override when allows_price_override is true on the charge. Sending price for any other charge is refused with 422, so you never bill something other than what you asked for.

What happens

Saasybill creates the invoice, then sends it to Xero. Whether Xero emails it follows the organisation’s default invoice status and minimum invoice amount.
A failed sync is not an error response. Don’t retry the request: the invoice already exists, and a new Idempotency-Key would bill the customer twice. Check xero.sync_status on the response instead.
The invoice has no subscription. Webhook events follow as for any invoice. See Webhook events.

Retries

Idempotency-Key is required, because a repeated request would otherwise be a second invoice and a second bill. A retry with the same key and body returns the first response. The invoice id is derived from the key, so a crash partway through can’t produce a second invoice.
Build the key from your own record of what you are billing, such as an order id. A random key on each attempt defeats the purpose.

When a request is refused

The organisation’s state decides some refusals. They answer 409, and nothing in the request can fix them. A problem with a field answers 422, and param names it. An unknown customer answers 404 customer_not_found, and an unknown charge answers 404 charge_not_found. See Errors.
A key made before invoices:write existed doesn’t have it. An owner or admin adds the scope to the key, or creates a new one. See Authentication.

Refunds

The API can’t credit a one-time invoice, and neither can the app. Raise a refund as a credit note in Xero.