Skip to main content
This walkthrough takes you from no key to a subscription with an invoice in Xero. Each step is one request.
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.
  1. Open Organisation Settings and go to Developer Settings, then API Keys.
  2. Click Create API Key.
  3. Enter a Name, such as Signup integration.
  4. Choose the Permissions the key needs. For this walkthrough, select all of them.
  5. Choose when the key Expires, or choose Never.
  6. Click Create Key.
Copy the key from the Your New API Key dialog. It is shown once and cannot be retrieved later.
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 200 response confirms the key works.
Note 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.