/api/v1/accounting/xero/start
auth: jwt (administrator)Begin a Xero OAuth2 authorisation flow for the caller's business. Generates a PKCE verifier + state, persists them in OAuthStates, and returns the Xero authorisation URL the app/browser must redirect to. Rate-limited (10/min open bucket).
handlers: XeroAuthController.start
No parameters.
APIResponseDataObject<XeroStartResponse>APIErrorAPIError/api/v1/accounting/xero/callback
auth: noneOAuth callback target hit by the user's browser after Xero consent. Validates the state (constant-time), exchanges the authorisation code, upserts XeroConnections rows for every tenant returned, and either 302-redirects (desktop) or serves a 200 text/html bridge page (mobile UA) that opens the native `vsms://auth/xero/...` deep link.
handlers: XeroAuthController.callback
| name | required | default | description |
|---|---|---|---|
code querystring | no | — | OAuth authorisation code returned by Xero on success. |
state querystring | no | — | Opaque PKCE state value previously issued by `/start`. Constant-time compared against OAuthStates row. |
error querystring | no | — | Set by Xero when the user denies consent or the flow fails. Triggers the failure bridge / failure deep link. |
error_description querystring | no | — | Human-readable error message from Xero (logged, sanitised before being exposed). |
redirecttext/html/api/v1/accounting/xero/status
auth: jwtConnection summary for the caller's business — whether a Xero connection exists, the active tenant, the list of authorised tenants (no tokens), and the current `autoFiscaliseInvoices` flag.
handlers: XeroAuthController.status
No parameters.
APIResponseDataObject<XeroStatusResponse>APIError/api/v1/accounting/xero/tenants
auth: jwtList every Xero tenant authorised for the caller's business. Each entry carries `isActive` to indicate which tenant is the current target of sync / webhooks.
handlers: XeroAuthController.tenants
No parameters.
APIResponseDataList<XeroTenantSummary>/api/v1/accounting/xero/connection
auth: jwt (administrator)Hard-disconnect Xero for the caller's business — deletes every XeroConnections row, drops encrypted tokens, fires `XERO_DISCONNECTED` audit.
handlers: XeroAuthController.disconnect
No parameters.
APIResponseDataObject<{ deletedCount: number }>/api/v1/accounting/xero/tax-mappings
auth: jwt (administrator)List all Xero tax-type to V-SDC tax-label mappings for the business (active and inactive). Active rows ordered first, then alphabetically. `isActive: boolean` per row so the admin UI can surface a Restore action on soft-deleted entries.
handlers: XeroTaxMappingsController.list
No parameters.
APIResponseDataList<TaxRateMappingDTO>/api/v1/accounting/xero/tax-mappings/auto-map
auth: jwt (administrator)Fetch Xero `/TaxRates` from the active tenant + V-SDC `/status`, then return match suggestions with `needsReview` flags + alternatives. Does NOT persist — the admin confirms each suggestion via PUT. Rate-limited (10/min open bucket).
handlers: XeroTaxMappingsController.autoMap
No parameters.
APIResponseDataObject<XeroTaxMappingAutoMapResponse>APIErrorAPIError/api/v1/accounting/xero/tax-mappings
auth: jwt (administrator)Create or update one Xero tax-type to V-SDC label mapping (MERGE on (businessId, 'xero', providerTaxType)). Re-activates an existing inactive row instead of inserting a duplicate. Fires `XERO_TAX_MAPPING_UPDATED` audit.
handlers: XeroTaxMappingsController.upsert
| name | required | default | description |
|---|---|---|---|
providerTaxType bodystring | yes | — | Xero tax-type code (e.g. `OUTPUT2`, `ZERORATED`). Trimmed, 1–100 chars. |
providerTaxName bodystring | null | no | — | Human-readable Xero tax name for display. |
providerRate bodynumber | null | no | — | Xero rate percent. |
vsdcTaxLabel bodystring | yes | — | Target V-SDC tax label (must be one of `F/N/P/E/T/A/B/C/D`). |
vsdcRate bodynumber | null | no | — | V-SDC rate percent for display. |
APIResponseDataObject<TaxRateMappingDTO>APIError/api/v1/accounting/xero/tax-mappings/:providerTaxType
auth: jwt (administrator)Soft-delete a Xero tax mapping — sets `IsActive=0`. Row is retained for history and can be re-activated via the restore endpoint. Idempotent.
handlers: XeroTaxMappingsController.remove
| name | required | default | description |
|---|---|---|---|
providerTaxType pathstring | yes | — | Xero tax-type code to deactivate. |
empty/api/v1/accounting/xero/tax-mappings/:providerTaxType/restore
auth: jwt (administrator)Re-activate a previously soft-deleted Xero tax mapping (`IsActive=0` → `1`). Idempotent.
handlers: XeroTaxMappingsController.restore
| name | required | default | description |
|---|---|---|---|
providerTaxType pathstring | yes | — | Xero tax-type code to re-activate. |
empty/webhooks/xero
auth: hmac (x-xero-signature)Xero-initiated webhook delivery. Verifies HMAC-SHA256 over the raw request body using `XERO_WEBHOOK_SIGNING_KEY` (constant-time compared to the base64 `x-xero-signature` header). Valid signature → fan each event to the `xero:webhook:events` Redis Stream and respond `200` within Xero's 5-second ack budget. Xero's intent-to-receive handshake (`events: []`) flows through the same code path. NOT mounted under `/api/v1`.
handlers: XeroWebhookController.handle
| name | required | default | description |
|---|---|---|---|
x-xero-signature headerstring | yes | — | Base64-encoded HMAC-SHA256 of the raw request body. |
events bodyXeroWebhookEvent[] | no | — | Array of event objects (`tenantId`, `tenantType`, `eventCategory`, `eventType`, `resourceId`, `resourceUrl`, `eventDateUtc`, `eventSequence`). Empty array is the intent-to-receive ping. |
firstEventSequence bodyinteger | no | — | Sequence number of the first event in the batch. |
lastEventSequence bodyinteger | no | — | Sequence number of the last event in the batch. |
entropy bodystring | no | — | Random salt included by Xero. |
emptyAPIErrorAPIError/api/v1/accounting/xero/sync
auth: jwt (administrator | view_invoices | submit_invoices)Pull-sync PAID invoices from the active Xero tenant: fetch via `XeroProvider.getInvoices`, normalise to `AccountingInvoice[]`, persist to `Invoices` table (`Source='xero'`) with one `ImportBatches` row per call. Idempotency key = `SHA-256(businessId:xeroTenantId:xeroInvoiceId)`. When `AutoFiscaliseInvoices=1`, newly-inserted eligible invoices are chunked (10) and dispatched as fiscalisation jobs. Returns the `AccountingInvoice[]` plus a summary message including `jobIds=`. HTTP caching disabled. Runs in the background: replies `202 { runId }` at once and stores the outcome on the run. The finished run's `result` is the old synchronous body: `data` is now an empty list, `totalRows` the fetched count and `message` the counters string.
handlers: AccountingInvoicesController.xeroSync
| name | required | default | description |
|---|---|---|---|
contactId querystring | no | — | Provider-native contact GUID — narrows the result to invoices for that contact. |
modifiedSince queryISO-8601 datetime | no | — | Only invoices updated after this date are returned (passed as `If-Modified-Since` to Xero). |
dateTo queryISO-8601 datetime | no | — | Post-fetch filter on `updatedAt` (Xero has no `dateTo` param). |
page queryinteger | no | — | 1-based page. Omit to auto-paginate. |
pageSize queryinteger | no | — | 1–100. Capped by the provider. |
APIResponseDataObject<BackgroundRunAcceptedDTO>APIErrorAPIErrorAPIErrorAPIError/api/v1/accounting/xero/connections/:connectionId/location
auth: jwt (administrator)Map one Xero organisation (connection) to the VSMS Location whose certificate signs its invoices. locationId is required but nullable: null clears the mapping and returns the organisation to the business-default fallback. A non-null assignment triggers a best-effort re-sync of the backlog that became signable. Returns the refreshed tenant list for the business. Assigning a location starts the business-wide blocked-invoice re-sync as a background run and replies without waiting for it; if a re-sync is already running, none is started.
handlers: XeroAuthController.setConnectionLocation
| name | required | default | description |
|---|---|---|---|
connectionId pathuuid | yes | — | XeroConnections row id (one row per organisation). |
locationId bodyuuid | null | yes | — | Location to map; null clears. Required — omission is rejected. |
APIResponseDataList<XeroTenantSummary>APIErrorAPIErrorAPIError/api/v1/accounting/xero/organisations/refresh
auth: jwt (administrator)Re-read the organisations on the stored Xero authorisation. Adds any the grant now covers as PENDING (not syncing until accepted) and refreshes the name and short code of those already held. It can only see organisations the existing authorisation already includes: granting access to a further organisation in Xero still needs the admin to reconnect.
handlers: XeroAuthController.refreshOrganisations
No parameters.
APIResponseDataList<XeroTenantSummary>APIError/api/v1/accounting/xero/connections/:connectionId/reject
auth: jwt (administrator)Decline one connected Xero organisation: it is forced disabled and stays that way until accepted again. Refused while a signing location is assigned - clear the mapping first.
handlers: XeroAuthController.rejectConnection
| name | required | default | description |
|---|---|---|---|
connectionId pathstring (uuid) | yes | — | Xero connection id (one per organisation). |
APIResponseDataObject<XeroTenantSummary>APIError/api/v1/accounting/xero/connections/:connectionId/accept
auth: jwt (administrator)Accept one Xero organisation: a PENDING one (newly authorised, not yet reviewed) or a rejected one coming back. Either way it becomes live - enabled and syncing - and unmapped, so its invoices are held until an admin assigns a signing location.
handlers: XeroAuthController.acceptConnection
| name | required | default | description |
|---|---|---|---|
connectionId pathstring (uuid) | yes | — | Xero connection id (one per organisation). |
APIResponseDataObject<XeroTenantSummary>APIError