Skip to main content
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 no units. 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.

CPI price increases

Set cpi_enabled to true and the plan price rises by the consumer price index at each annual renewal. Saasybill measures the change in CPI over the billing interval, applies it to the plan price, and notes the percentage on the renewal invoice line. Each increase builds on the last. On a plan that bills meters, the meter rates rise by the same factor.
The response carries cpi_enabled: true, and so does every later read of the subscription.
If the first renewal invoice is raised as the subscription is created, which happens when the renewal date is within the organisation’s Invoice Creation Date, that invoice already includes the increase.
A renewal never waits for CPI data. If no figure is available for the organisation’s country, the renewal is held until an Owner or Admin sets a manual rate or turns CPI off for the subscription.

Start in the future

Set start_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 as invoice.
A new subscription answers 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 read invoice.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. It is also null for a plan with no recurring fee sold with no charges, because there is nothing to bill for its first period. Its usage is billed when the period ends.

Validation errors

A field that breaks a rule answers 422, and param names the field.
Other refusals aren’t about a single field: