> For the complete documentation index, see [llms.txt](https://api.qvalia.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://api.qvalia.io/api-documentation/apis/ways-to-authenticate.md).

# Ways to authenticate

Every Qvalia Public API endpoint accepts either:

* an **API key**, sent as the `Authorization` header, or
* a short-lived **JWT access token**, sent as `Authorization: Bearer <token>`.

#### API key access

Every Qvalia account has an API key, which is a long-lived secret that can be used to authenticate as that account.

The API key is sent in the `Authorization` header as:

```http
Authorization: <api_key>
```

The API key is issued by Qvalia and can be rotated or revoked using Qvalia's portal, or through Qvalia Helpdesk. You'll find your API key in the Qvalia portal under API & SFTP settings.

If you are a Partner, your API key is issued to your Partner account, and you will use your own `partnerRegNo` as the `accountRegNo` when authenticating.

***It is the responsibility of the account holder to keep the API key secret!***

API keys cannot be retrieved again after they have been issued, so store yours securely. If you lose your API key, you can generate a new one in the Qvalia portal.

#### JWT access token through the `/token` endpoint

Use `/token` to exchange your credentials for a JWT. There are three ways to do this, depending on your role and who you want to authenticate as:

1. **Authenticate as yourself (`accountRegNo` in the URI)**. Call `GET` or `POST /token/{accountRegNo}` with your own `accountRegNo` in the URI and your API key in the `Authorization` header. This also applies if you are a Partner: a Partner always authenticates using its **own** `partnerRegNo` as the `accountRegNo` — never a child account's regNo. Access to a specific child account (e.g. via `/partner/{partnerRegNo}/...` endpoints) is granted on the Partner's child account.
2. **Partner acting on behalf of a child account (`actingAs: parent`)** — a Partner can request a token scoped to one of its child accounts by `POST`'ing to `/token/{partnerRegNo}` (or `/token`, see below) with `actingAs: parent` and `forChildRegNo: <childAccountRegNo>` in the body. The Partner must be authorized to act on behalf of that child. The resulting token's `sub` claim is the child account, so it can be used to call endpoints that operate directly on the child account (e.g. SCIM user provisioning) on the child's behalf, meaning that `/partner/{partnerRegNo}` can be omitted from the URI when calling a child's account, e.g. `/transaction/{accountRegNo}`. Such a token acts for that one child and nothing else: it is not valid on the Partner API (`/partner/...` answers `401`), which takes your own API key or your own token (option 1) with your `partnerRegNo` in the URI.
3. **Client credentials (no `accountRegNo` in the URI)** — instead of putting `accountRegNo` in the URI and the API key in the `Authorization` header, you may `POST` to `/token` with `client_id` (your `accountRegNo`) and `client_secret` (your API key) either in the body, or as HTTP Basic auth (`Authorization: Basic base64(client_id:client_secret)` — the convention most OAuth2 client libraries default to). This is functionally equivalent to option 1 (or option 2, if combined with `actingAs: parent`), and is useful for clients that model authentication as an OAuth2-style client-credentials exchange.

Tokens expire after one hour.

#### Renewing a token

`GET` or `POST /token/{accountRegNo}` also takes a token that has not expired, as `Authorization: Bearer <token>`, and answers with a new one for the same account. A token acting on behalf of a child account (`actingAs: parent`) is renewed with the child's `accountRegNo` in the URI, and as what it is: the new token acts for the same child, on behalf of the same Partner.

**A token can be renewed with a token for 6 hours after the API key was last presented.** After that `/token` answers `401` and you authenticate with the API key again. This also covers a token for a child account requested with a Partner's token: it counts from when the Partner last presented its API key. The token itself keeps working on every other endpoint until it expires. A client that only ever renews with its token therefore gets a `401` from `/token` six hours after it started, and has to keep the API key at hand.


---

# 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://api.qvalia.io/api-documentation/apis/ways-to-authenticate.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.
