> 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/procountor.md).

# Procountor

Complete Procountor onboarding from your client backend.

**Preview** · [What this means for your integration](https://docs.zwapgrid.com/onboarding-flow/headless-onboarding/headless-onboarding.md#preview)

Your customer selects the company in Procountor. Your backend sends the unused authorization code and callback URL. **Zwapgrid exchanges the code and manages token refresh.**

First, complete the [shared prerequisites and example setup](https://docs.zwapgrid.com/onboarding-flow/headless-onboarding/headless-onboarding.md#before-you-start).

## What you need

* Your own Procountor application and access to a supported company in Sweden, Denmark or Finland. See the [Procountor setup guide](https://docs.zwapgrid.com/client-portal/systems/setup-guides/procountor.md).
* A Published Procountor System Setting containing that application's client ID and secret, belonging to your Zwapgrid client.
* A backend callback registered for that application, without a query string. Procountor registers one callback per application: use a separate application if your existing one is used for guided onboarding.
* Confirmation from Zwapgrid of which Procountor host to use: `https://pts-api.procountor.com` for test or `https://api.procountor.com` for live. Authorization, code exchange and refresh must use the same host.

## OAuth scopes

This Procountor authorization request does not send a `scope` parameter.

## 1. Prepare the connection

1. Use the [Consent created in the shared workflow](https://docs.zwapgrid.com/onboarding-flow/headless-onboarding/headless-onboarding.md#1-create-a-consent). Make sure `systemsSettings.procountor` contains your published setting ID.
2. Start authorization at the selected provider host's `/login` route with `response_type=code`, your `client_id`, registered `redirect_uri` and random, expiring session/Consent-bound `state`.
3. The customer logs in, selects the company and approves access in Procountor. Validate callback state on your backend; do not exchange the returned code.
4. Submit the unused code and exact redirect URI promptly, within its five-minute lifetime. Zwapgrid exchanges it and verifies company access and a supported company country (SE, DK or FI). No additional company selection is needed.

This flow requires a user who can sign in and select a company. Procountor API-login-only users need its separate machine-to-machine (M2M) flow. See [Procountor authentication](https://dev.procountor.com/api-authentication/).

## 2. Send the request

```json
{
  "source": "procountor",
  "credentials": {
    "authorizationCode": "<unused-authorization-code>",
    "redirectUri": "https://client.example/procountor/callback"
  }
}
```

Both fields are required, at most 2048 characters each. Redirects must be HTTPS (HTTP loopback is accepted locally), with no query, fragment or user information. Do not send tokens, tenant/company/environment fields or a PKCE verifier.

Replace the placeholders and save this body as a protected `connection.json` on your backend. Set the [example variables](https://docs.zwapgrid.com/onboarding-flow/headless-onboarding/headless-onboarding.md#set-up-the-examples), including a new UUID in `CORRELATION_ID`, then send the request once:

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

## 3. Check the result

Expect HTTP 201 with `source: procountor` and `state: completed`. [Optionally verify the connection](https://docs.zwapgrid.com/onboarding-flow/headless-onboarding/headless-onboarding.md#optional-verify-the-connection). Zwapgrid uses the selected application for token refresh.

Submit once. A GET 404 does not mean the code is safe to reuse. If you cannot confirm the result, authorize again; never automatically replay the code.


---

# 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/procountor.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.
