vsmsconnect — API — sage

← all endpoints

GET/api/v1/accounting/sage/start auth: jwt (administrator)

Begin a Sage OAuth2 authorisation flow for the caller's business. Generates PKCE + state, persists in OAuthStates, returns the Sage authorisation URL. Rate-limited (10/min open bucket).

handlers: SageAccountingAuthController.start

Inputs

No parameters.

Outputs

200
APIResponseDataObject<SageStartResponse>
`{ authorizationUrl }`.
409
APIError
BUSINESS_CONTEXT_REQUIRED.
429
APIError
Rate limit exceeded.
GET/api/v1/accounting/sage/callback auth: none

Sage OAuth callback. Validates state, exchanges the code, upserts a single SageConnections row (Sage has one business per token — no tenant selection), then 302 redirects (desktop) or serves a 200 text/html bridge page (mobile) opening `vsms://auth/sage/{success|failure}`.

handlers: SageAccountingAuthController.callback

Inputs

namerequireddefaultdescription
code query
string
no—OAuth authorisation code returned by Sage.
state query
string
no—PKCE state issued by `/start`.
error query
string
no—Set by Sage on failure or user denial.

Outputs

302
redirect
Desktop UA — redirect to `${SAGE_FRONTEND_WEB_BASE_URL}/auth/sage/{success|failure}`.
200
text/html
Mobile UA — HTML bridge page opening the native deep link with web fallback.
GET/api/v1/accounting/sage/status auth: jwt

Sage connection summary — whether a Sage connection exists, the connected Sage business, and the current `autoFiscaliseInvoices` flag.

handlers: SageAccountingAuthController.status

Inputs

No parameters.

Outputs

200
APIResponseDataObject<SageStatusResponse>
Connection summary.
409
APIError
BUSINESS_CONTEXT_REQUIRED.
DELETE/api/v1/accounting/sage/connection auth: jwt (administrator)

Soft-deactivate the Sage connection for the caller's business (`IsActive=0`). Rows are retained for history; the user may re-authorise via `/sage/start`. Fires `SAGE_DISCONNECTED` audit.

handlers: SageAccountingAuthController.disconnect

Inputs

No parameters.

Outputs

200
APIResponseDataObject<{ deactivatedCount: number }>
Number of rows deactivated.
GET/api/v1/accounting/sage/tax-mappings auth: jwt (administrator)

List all Sage tax-type to V-SDC tax-label mappings for the business (`Provider='sage'`). Mirrors `/accounting/xero/tax-mappings`.

handlers: SageAccountingTaxMappingsController.list

Inputs

No parameters.

Outputs

200
APIResponseDataList<TaxRateMappingDTO>
Sage mappings (active and inactive, active first).
POST/api/v1/accounting/sage/tax-mappings/auto-map auth: jwt (administrator)

Pull Sage tax-rates + V-SDC `/status` and return match suggestions. Does NOT persist. Rate-limited (10/min open bucket).

handlers: SageAccountingTaxMappingsController.autoMap

Inputs

No parameters.

Outputs

200
APIResponseDataObject<SageTaxMappingAutoMapResponse>
Suggestions array.
401
APIError
REAUTH_REQUIRED — Sage refresh token rejected.
PUT/api/v1/accounting/sage/tax-mappings auth: jwt (administrator)

Create or update one Sage tax-mapping. Re-activates an inactive row on match. Fires `SAGE_TAX_MAPPING_UPDATED` audit (resource type `SAGE_CONNECTION`).

handlers: SageAccountingTaxMappingsController.upsert

Inputs

namerequireddefaultdescription
providerTaxType body
string
yes—Sage tax-type code.
providerTaxName body
string | null
no—Human-readable Sage tax name.
providerRate body
number | null
no—Sage tax rate.
vsdcTaxLabel body
string
yes—V-SDC label — one of `F/N/P/E/T/A/B/C/D`.
vsdcRate body
number | null
no—V-SDC rate percent.

Outputs

200
APIResponseDataObject<TaxRateMappingDTO>
Upserted mapping.
422
APIError
SAGE_TAX_MAPPING_INVALID_LABEL — invalid `vsdcTaxLabel`.
DELETE/api/v1/accounting/sage/tax-mappings/:providerTaxType auth: jwt (administrator)

Soft-delete a Sage tax-mapping (`IsActive=0`). Idempotent.

handlers: SageAccountingTaxMappingsController.remove

Inputs

namerequireddefaultdescription
providerTaxType path
string
yes—Sage tax-type code to deactivate.

Outputs

204
empty
No content.
PATCH/api/v1/accounting/sage/tax-mappings/:providerTaxType/restore auth: jwt (administrator)

Re-activate a deactivated Sage tax-mapping (`IsActive=1`). Idempotent.

handlers: SageAccountingTaxMappingsController.restore

Inputs

namerequireddefaultdescription
providerTaxType path
string
yes—Sage tax-type code to re-activate.

Outputs

204
empty
No content.
GET/api/v1/accounting/sage/sync auth: jwt (administrator | view_invoices | submit_invoices)

Pull-sync invoices from the active Sage connection. Fetches OUTSTANDING / OVERDUE / PAID via three API calls merged client-side, normalises, persists to `Invoices` (`Source='sage'`). Idempotency key = `SHA-256(businessId:sageBusinessId:sageInvoiceId)`. `modifiedSince` is silently ignored (Sage's `sales_invoices` has no date filter). Auto-fiscalisation behaviour matches Xero. 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.sageSync

Inputs

namerequireddefaultdescription
contactId query
string
no—Sage contact id — narrows the result to one contact.
modifiedSince query
ISO-8601 datetime
no—Silently ignored for Sage.
dateTo query
ISO-8601 datetime
no—Post-fetch filter on `updatedAt`.
page query
integer
no—1-based page.
pageSize query
integer
no—1–100.

Outputs

202
APIResponseDataObject<BackgroundRunAcceptedDTO>
Started in the background: `{ runId }`. Poll `GET /api/v1/businesses/:businessId/background-runs/:runId`; once `status` is `done`, `result` holds the response body this endpoint used to return.
409
APIError
BACKGROUND_RUN_IN_PROGRESS — a Sync Now for this provider and business is already running. `data` is `BackgroundRunInProgressDTO` (`runId`, `kind`, `params`, `startedAt`) of the running run.
401
APIError
REAUTH_REQUIRED — Sage refresh token rejected.
409
APIError
ACCOUNTING_PROVIDER_NOT_CONFIGURED.
429
APIError
SAGE_RATE_LIMITED.