You need a Saasybill organisation connected to Xero, with at least one plan and one customer. If you are testing, read Testing first and use a Xero Demo Company.
Before you start
1
Create an API key
Only an owner or admin can create keys.
- Open Organisation Settings and go to Developer Settings, then API Keys.
- Click Create API Key.
- Enter a Name, such as
Signup integration. - Choose the Permissions the key needs. For this walkthrough, select all of them.
- Choose when the key Expires, or choose Never.
- Click Create Key.
2
Store it as an environment variable
Keep the key out of your code and your repository.
Make your first subscription
1
Check the connection
Retrieve the organisation. A Note
200 response confirms the key works.setup_mode. While it is true, Saasybill creates subscriptions but does not raise invoices in Xero.2
Find the plan
Look up the plan by the code you gave it in the app.
Response
3
Find the customer
Customers come from Xero. Look one up by the code you use for them.If the customer doesn’t exist yet, see Customers and Xero.
4
Create the subscription
Send the customer, the plan and the units. The
Idempotency-Key is required. Use an id from your own system, such as the signup id, so a retry can never bill twice.Response (trimmed)
5
Check the invoice reached Xero
Read
invoice.xero.sync_status. synced means the invoice is in Xero. failed means Xero refused it, but the subscription still exists. See Create a subscription.6
Change the units
When the customer adds seats, send the new total, not the difference.The response’s
change object says what Saasybill did. See Change units.Next steps
Create a subscription
Every option, with request bodies for common cases.
Set up webhooks
Hear about paid invoices without polling.
Handle errors
Branch on error codes, not messages.
Retry safely
How idempotency keys protect against double billing.