This page covers the API. To end or restore a subscription in the app, see Subscriptions. For the lifecycle, see Subscriptions explained.
subscriptions:write scope. Both return the updated subscription.
End a subscription
POST /v1/subscriptions/{id}/end takes a single required field, when.
Ending a subscription doesn’t refund or credit the current period. The customer keeps what they’ve paid for.
End at period end
End now
Withnow you can also clean up the subscription’s invoices in Xero, and choose when its final usage is invoiced. All three options default to false, so Saasybill leaves your accounting documents alone and waits the organisation’s usage grace period unless you say otherwise.
All three are refused, with
422, when when is period_end. Invoices are only removed or raised early when a subscription ends now.
Deferred line items
A subscription can hold deferred line items: lines generated but not yet invoiced, which wait for the next renewal invoice. An ending subscription has no renewal to carry them, sodeferred_items says what to do with them.
invoice_at_period_end with when: now is refused with 422, and param is deferred_items. The field is ignored when there are no deferred items.
If you leave deferred_items out, the organisation’s Deferred Items on End setting decides. A request that includes the field always wins over the setting.
Set a default for the organisation
An owner or admin can change the default under Developer Settings, then Configuration. The setting is called Deferred Items on End.The default applies to both
now and period_end. With period_end, Invoice them now invoices the items at the call, not on the end date. invoice_at_period_end isn’t a setting option, so send it in the request when you want it.Ending near renewal
If the next period’s renewal invoice has already been raised, a subscription that won’t renew has no use for it. Ending the subscription, now or at period end, voids the invoice in Xero if it was approved, or deletes it. Restoring later raises the invoice again. The end is refused while that invoice has a payment or credit on it, because the customer has already paid for the next period. The answer is409 invalid_state. To end it after that period, change End after in the subscription’s details in the app.
When it can’t be ended
A subscription that can’t be ended answers409 invalid_state, with a message that says why. Examples include a subscription that has already ended, and Setup Mode when you ask to remove invoices, because nothing can be changed in Xero.
Restore a subscription
POST /v1/subscriptions/{id}/restore undoes an end. It takes an empty JSON object.
- a subscription set to end at period end, which goes back to renewing
- an
endedsubscription, before its renewal date
When it can’t be restored
A subscription that can’t be restored answers409 invalid_state, with a message that says why.
Webhook events
Both actions send webhooks.
See Webhook events.