> For the complete documentation index, see [llms.txt](https://docs.zwapgrid.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zwapgrid.com/onboarding-flow/headless-onboarding/headless-onboarding.md).

# Overview

Connect your customers' accounting systems from your backend.

With headless onboarding, your application manages the connection screens for your customers. Your backend sends their authorization or credentials to the Consent API. Zwapgrid checks access, connects the accounting system and accepts the Consent.

This guide is for developers building that backend. In these guides, **you** means the client integrating with Zwapgrid; **your customer** means the company connecting its accounting system.

Your backend must complete three steps:

1. Create a Consent for your customer.
2. Obtain authorization or credentials for their accounting system.
3. Send one connection request to Zwapgrid.

After a successful response, you can optionally [check the connection and read accounting data](#optional-verify-the-connection).

For OAuth systems, your customer still signs in and approves access at the provider. Zwapgrid manages token refresh after the connection is complete. You can also use the [guided Onboarding Flow](https://docs.zwapgrid.com/onboarding-flow/onboarding-flow.md) to let Zwapgrid host the connection screens.

## Preview

{% hint style="info" %}
Headless Onboarding is in **Preview**. The feature and its API may change or improve with short notice. Check the documentation when updating your integration.
{% endhint %}

## Before you start

You need:

* The accounting system enabled for your client in the Client Portal.
* A published [System Setting](https://docs.zwapgrid.com/client-portal/systems/system-settings.md) for the application or provider environment you will use. Your system's guide explains the requirements and any supported defaults.

## Security

Keep each onboarding attempt bound to the correct customer session and Consent, and confirm that the selected company is the one your customer intends to connect. For OAuth, validate `state` at your backend callback before using the code. Keep credentials on your backend and never share them between customer sessions. Mixing sessions or credentials can connect the wrong company and expose its data.

## Choose your system

Each system has a different connection request. Open its guide for the exact steps and JSON body.

| System and guide                                                                                      | `source` value     | What you send                                                     | How the company is chosen                           |
| ----------------------------------------------------------------------------------------------------- | ------------------ | ----------------------------------------------------------------- | --------------------------------------------------- |
| [Fortnox](https://docs.zwapgrid.com/onboarding-flow/headless-onboarding/fortnox.md)                   | `fortnox`          | Unused authorization code and redirect URI                        | Your customer authorizes the company in Fortnox     |
| [Xero](https://docs.zwapgrid.com/onboarding-flow/headless-onboarding/xero.md)                         | `xero`             | Access token, refresh token and tenant ID                         | Your backend selects an accessible organization     |
| [Business Central](https://docs.zwapgrid.com/onboarding-flow/headless-onboarding/business-central.md) | `businesscentral`  | Access token, refresh token, tenant, environment and company      | Your backend selects an environment, then a company |
| [Procountor](https://docs.zwapgrid.com/onboarding-flow/headless-onboarding/procountor.md)             | `procountor`       | Unused authorization code and redirect URI                        | Your customer selects the company in Procountor     |
| [Bokio](https://docs.zwapgrid.com/onboarding-flow/headless-onboarding/bokio.md)                       | `bokio`            | Unused authorization code and redirect URI                        | Your customer selects the company in Bokio          |
| [Spiris](https://docs.zwapgrid.com/onboarding-flow/headless-onboarding/spiris.md)                     | `vismaeaccounting` | Unused authorization code and redirect URI; PKCE verifier if used | Your customer selects the company in Spiris         |
| [Björn Lundén](https://docs.zwapgrid.com/onboarding-flow/headless-onboarding/bjorn-lunden.md)         | `bjornlunden`      | Company public key                                                | The key identifies the company                      |
| [Netvisor](https://docs.zwapgrid.com/onboarding-flow/headless-onboarding/netvisor.md)                 | `vismanetvisor`    | User identifier, customer key and business ID                     | The business ID identifies the company              |

## Set up the examples

Run the cURL examples on your backend. Replace placeholders such as `<consent-UUID>` with your own values. Set these variables before running a request:

| Variable                | Value to use                                                                                                                                                               |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `CONSENTS_API_BASE_URL` | The Consent API base URL from the [API Reference](https://apidocs.zwapgrid.com/), without a trailing slash or `/api/v1`. Keep any gateway prefix included in the base URL. |
| `ZWAPGRID_API_KEY`      | Your backend API key for the selected client and environment.                                                                                                              |
| `CORRELATION_ID`        | A new non-empty UUID for each request. Also called a GUID; retain it to help trace requests with support.                                                                  |
| `CONSENT_ID`            | The Consent ID returned when you create a Consent in step 1.                                                                                                               |

Keep API keys, application secrets, codes and tokens on your backend. Exclude OAuth callback query parameters from logs and redirect to a clean URL after processing. Never include credentials in browser storage or support messages.

The examples read JSON from a file. Restrict the file to your backend user and delete it when finished. In your application, use protected memory or secret storage for credentials.

## OAuth scopes

Use the scopes listed in your system's guide. Where scopes are configurable in your Published System Setting, use the same scopes in that setting and your backend authorization request.

## 1. Create a Consent

Create one new Consent for the company you want to connect. Use the same client and API-key environment for Consent creation, connection creation and accounting reads.

Select your published setting in `systemsSettings`, using the `source` value from the table above. For example, save this Fortnox request as `consent.json`:

```json
{
  "name": "Headless onboarding",
  "systemsSettings": {
    "fortnox": "<published-system-settings-UUID>"
  }
}
```

Then send it:

```sh
curl --include --request POST \
  "$CONSENTS_API_BASE_URL/api/v1/consents" \
  --header "x-api-key: $ZWAPGRID_API_KEY" \
  --header "x-correlation-id: $CORRELATION_ID" \
  --header 'Content-Type: application/json' \
  --data-binary @consent.json
```

The response is HTTP **201**. Take the Consent ID from the response's `Location` header and set `CONSENT_ID` to that ID.

The setting must be Published and belong to your client and accounting system. Fortnox, Xero, Business Central, Procountor, Spiris and Bokio require you to select your application's setting on the Consent. For Björn Lundén and Netvisor, follow the guide if you intend to use a default. Choose settings here, before creating the connection.

See [Create Consent](https://docs.zwapgrid.com/client-portal/consents/create-consent.md) for more details. The Consent must still have status `Created` and no existing connection when you submit credentials.

## 2. Follow your system's authorization steps

Open your [system guide](#choose-your-system) and complete its authorization or credential-collection steps. It explains what you must do and what Zwapgrid handles.

For OAuth, your backend must check the callback's `state` value against a random, expiring value stored for that customer's session and Consent. This confirms that the callback belongs to the connection you started.

* **Fortnox, Procountor, Spiris and Bokio:** send the unused code to Zwapgrid. Zwapgrid exchanges it for tokens.
* **Xero and Business Central:** your backend exchanges the code and selects the company first, then sends tokens and the selected company details to Zwapgrid.
* **Björn Lundén and Netvisor:** collect the company credentials described in the guide. There is no customer OAuth callback.

## 3. Send the connection request

Use the JSON body and cURL command in your system guide to call:

```
POST /api/v1/consents/{consentId}/connection
```

Use your `x-api-key`, a new UUID in `x-correlation-id`, and `Content-Type: application/json`. Send only the documented fields. The maximum body size is 16 KiB; query parameters and additional fields are rejected. Application secrets stay in System Settings.

Send the request **once**. Turn off automatic retries for this POST, including retries after timeouts. If you cannot tell whether it succeeded, check the connection as described below.

A successful response is HTTP **201** with this body and `Cache-Control: no-store`:

```json
{
  "id": "<connection-UUID>",
  "source": "<submitted-source>",
  "state": "completed"
}
```

Zwapgrid has completed the connection and accepted the Consent. It does not return credentials or tokens. A connection request cannot replace an existing connection.

## Optional: Verify the connection

After a successful HTTP 201 response, no additional request is needed to complete headless onboarding. You can use the GET below to check the connection. Use this same GET to recover the result if the POST response is lost.

Set a new `CORRELATION_ID`, then read the connection:

```sh
curl --request GET \
  "$CONSENTS_API_BASE_URL/api/v1/consents/$CONSENT_ID/connection" \
  --header "x-api-key: $ZWAPGRID_API_KEY" \
  --header "x-correlation-id: $CORRELATION_ID"
```

HTTP **200** returns the same `id`, `source` and `state: completed`. Check that they match the connection you created.

You can also [read accounting data](https://docs.zwapgrid.com/get-started/access-your-customer-data.md) using that Consent to verify data access. This is optional and is not required to complete headless onboarding.

## If the result is uncertain

If POST times out or you lose its response:

1. **Do not submit the credentials again.** Run the [connection GET above](#optional-verify-the-connection) for the same Consent.
2. If GET returns **200** with the expected completed connection, onboarding is complete.
3. If it returns **404**, confirm the Consent ID, client and API-key environment. A missing connection does not mean a code is unused or a refresh token is still valid.
4. If you still cannot confirm the result, contact [Zwapgrid support](mailto:support@zwapgrid.com) with the Consent ID, UTC timestamp and correlation IDs for both requests. For OAuth systems, authorize again if you cannot confirm whether the code or tokens are still usable.

For **Xero and Business Central**, stop any refresh running in your backend and wait for it to finish **before** submitting tokens. Keep it stopped while checking an uncertain result. After success, let Zwapgrid refresh this authorization; do not refresh it yourself or use the same refresh tokens for another connection.

Authorization codes can be used once, and a refresh can replace the submitted refresh token before a later step fails. This is why repeating a POST after a lost response is unsafe. The correlation ID helps trace requests; it does not make repeated requests safe. Send one connection request at a time for a Consent.

## Common errors

| HTTP status     | What to do                                                                                                                            |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| 400             | Check the request fields, selected settings and access to the selected company. For a used or expired OAuth code, authorize again.    |
| 401 / 403       | Check your API key and whether the system is enabled for your client.                                                                 |
| 404             | Check the Consent ID, client and API-key environment. After an uncertain POST, follow the recovery steps above.                       |
| 409             | Check the Consent's current status and connection. It may already be linked, inactive or have another connection request in progress. |
| 413             | Keep the body within 16 KiB and use only the fields in your system's example.                                                         |
| 429             | Wait before reading again, following any retry guidance. Do not automatically repeat a connection POST.                               |
| 502 / 503 / 504 | Check the connection with GET and retain correlation IDs for support.                                                                 |

## API reference

See the [API Reference](https://apidocs.zwapgrid.com/) for Consent and Accounting operations, including connection creation and recovery. Use these guides for the complete onboarding workflow and system-specific examples.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.zwapgrid.com/onboarding-flow/headless-onboarding/headless-onboarding.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
