Finance connections to Xero
Connect an entity to its Xero organisation and Finance posts the entity's ready journals there, each once, with backoff on failure, a not-synced report and nothing sent until someone connects.
Files come first: an export file works on every install and makes no outbound call. A connection is the optional second way. Once an owner, admin or controller connects an entity to its Xero organisation, Finance posts the entity's ready journals to Xero as manual journals, each one once. Nothing is sent to Xero until someone connects, and disconnecting deletes the connection's tokens.
Connections live in Finance > Connectors > Connections (/finance/connectors?tab=connections), with the
Connectors module (finance.connectors). With the module off, the page, the tools and the REST routes answer 403
product_not_enabled. An entity posts to one accounting system at a time: for QuickBooks Online, see
Finance connections to QuickBooks Online.
Before you start: Xero on this install
Xero needs an app registered by whoever runs the install, at developer.xero.com, with the redirect URI
https://<your cloud>/api/workspace/finance/connections/callback. The operator sets its credentials as environment
variables:
| Variable | What |
|---|---|
XERO_CLIENT_ID |
the Xero app's client id |
XERO_CLIENT_SECRET |
the Xero app's client secret |
With either unset, Xero is not configured on the install: the Connect Xero button does not appear, the tools say so,
and nothing calls Xero. The install also needs its vault key (VENOM_VAULT_KEYS) to keep the tokens.
Connect an entity
On the Connections tab, each entity you may connect has Connect Xero. You need reference.write on the entity: a
controller there, or an owner or admin. Agents never connect, and no tool does: connecting is a consent you give in the
browser.
- Finance sends your browser to Xero's consent screen, with PKCE (S256) and a one-time state tied to you and your organisation, good for ten minutes.
- You pick the Xero organisation and approve. Finance asks for
offline_access,accounting.settings.read,accounting.contacts,accounting.manualjournalsandaccounting.invoices. - Xero sends you back. The state is used once; someone else's browser, a second use or a late return is refused. The tokens are sealed in the vault and never shown, logged or returned by a tool.
The entity's functional currency must be the Xero organisation's base currency: manual journals go to Xero in the functional amounts. Account codes must exist in Xero's chart of accounts, and dimensions are sent as Xero tracking categories by name (the first two).
What is posted, and when
The sweep cron runs every minute. For each active connection it takes the entity's ready journals (and failed ones
whose next try is due), oldest number first, at most 50 a run, and posts each as a Xero manual journal with status
POSTED, its narration the journal's number and memo. Each one:
- is posted at most once. Before any call Finance records the journal against the connection with an idempotency key,
and sends that key to Xero (
Idempotency-Key). If Xero made the entry but the answer never arrived, the next try sends the same key and Xero returns the entry it already made. - is never posted while it is in an open export file, and never once it is posted (by an export file someone confirmed, or by an earlier run). An export file and the connection never both post the same journal.
- once Xero accepts it, is marked posted with
external_refxero:<ManualJournalID>.
When a post fails, the journal is marked failed and one sync_failed exception goes on the
exceptions queue (one per journal, however many tries):
| Failure | What happens |
|---|---|
| No answer, a network error, Xero 5xx | tried again with the same key after 1 minute, then 2, 4, 8 … up to 6 hours |
| Xero refused the journal (a validation error) | not tried again until a person fixes it and retries the journal (finance_journal_retry); it then goes out under a new key |
| Xero's rate limit (429) | nothing changes on the journal; the connection waits for Xero's Retry-After |
| Xero refused the tokens, even after a refresh | the connection shows Needs reconnecting and posting stops until someone reconnects |
Access tokens are refreshed when they are about to expire, under a lock, so two refreshes at once never use Xero's single-use refresh token twice. A 401 refreshes once and tries again.
Sync now (a person with journals.write on the entity, a controller) runs the connection at once and ignores the
backoff, not Xero's rate limit.
The not-synced report
Open a connection to see the entity's ready and failed journals that are not in Xero yet, each with why:
- In an open export file: waiting for that file to be confirmed or cancelled;
- Waiting for the next sync;
- Retry scheduled: with the attempts so far, the next try and the last error;
- Failed: needs a person: Xero refused it; fix it and retry the journal;
- Connection not active: the connection is pending, needs reconnecting or is disconnected.
Below it are the connection's recent runs: when, scheduled or Sync now, how many were pushed, failed and deferred.
Disconnect
Disconnect deletes the connection's tokens and revokes them at Xero, and nothing more is posted. Journals already
posted stay posted. It needs reference.write on the entity and the console or finance:admin. An agent never
disconnects. Reconnecting the same entity later reuses its connection, so what was already posted is not posted again.
Tools and REST
| Tool | REST | What |
|---|---|---|
finance_connection_list |
GET /api/v1/finance/connections |
the connections, each with its system, and which systems are configured on this install |
finance_connection_get |
GET /api/v1/finance/connections/{id} |
one connection, its last runs and the not-synced report |
finance_connection_sync |
POST /api/v1/finance/connections/{id}/sync |
Sync now: journals.write, finance:write; for an agent, a decision its job's authority must grant |
finance_connection_disconnect |
POST /api/v1/finance/connections/{id}/disconnect |
disconnect: a person only, finance:admin |
Connecting has no tool: GET /api/workspace/finance/connections/connect?entity_id=&system=xero sends a signed-in person to Xero and
GET /api/workspace/finance/connections/callback brings them back.
Outbound hosts
A connection is an opt-in outbound integration (an exception to Petawork's no-outbound-call rule, named in
CLAUDE.md). With no active connection, or with Xero not configured on the install, Petawork Cloud makes no call to
Xero at all. With one, it calls only these hosts, over https, through the same guard as every other outbound call (no
redirects followed, private addresses refused):
| Host | What for |
|---|---|
login.xero.com |
the consent screen (your browser goes there, not the cloud) |
identity.xero.com |
/connect/token (tokens and refresh) and /connect/revocation (on disconnect) |
api.xero.com |
/connections (which organisation you picked) and /api.xro/2.0 (manual journals; accounts, tax rates, contacts and tracking categories when read) |
Bills and payments are not posted yet: Finance has none until Payables and Payments arrive.