This page covers the API. To create a subscription by hand, see Subscriptions. The API applies the same rules as the New Subscription form.
POST /v1/subscriptions creates the subscription and its first invoice, and sends the invoice to Xero. It needs the subscriptions:write scope and an Idempotency-Key.
Choose the customer and the plan
Identify each by id or by code. Send exactly one of each pair.
Codes are your own references and are unique in the organisation. They mean you don’t have to store Saasybill ids. If a customer doesn’t exist yet, see Customers and Xero.
Request fields
Money and percentages accept up to two decimal places, as a string or a number.
Examples
A per unit plan
The usual signup: find the customer and plan by your own codes.A flat fee plan with a fixed term
A flat fee plan takes nounits. Here the plan allows its price to be overridden, and the subscription ends after 12 cycles.
Add charges
A charge is a one-off fee that goes on the first invoice and doesn’t recur. Send charges by id, from the charges list.
Charges must be active and in the plan’s currency.
Start in the future
Setstart_date to a later date and the subscription is created as pending. It goes live on that date.
The earliest start_date is one billing period back, plus a day. In Setup Mode the date is the previous renewal date of a subscription that is already running, so it can’t be in the future.
The response
The response is the subscription with the first invoice attached asinvoice.
201. Save the subscription’s id against your own customer record so you can change its units later.
Check the invoice
Creating a subscription and pushing its invoice to Xero are two steps. The second can fail without undoing the first, so always readinvoice.xero.sync_status.
A failed sync is still a
201. Sending the same request with the same Idempotency-Key returns this same response and doesn’t raise a second invoice.
In Setup Mode no invoice is raised, so
invoice is null.Validation errors
A field that breaks a rule answers422, and param names the field.
Other refusals aren’t about a single field: