API authentication
Every request to the API runs on behalf of an invoiceR user. The application has exactly the permissions this user has through their roles.
invoiceR supports two ways of logging in to the API:
| Method | Header | Validity | Suitable for |
|---|---|---|---|
| Access token | Authorization: Bearer <token> | short, issued anew at every login | Applications that may know user name and password |
| Personal access token (PAT) | Authorization: PAT <token> | until the chosen expiry date, one year by default | Services and scripts that should run without a password |
Access token with user name and password
Section titled “Access token with user name and password”-
Send the user name (or e-mail address) and password to
POST /api/TokenAuth/Authenticate:POST https://<server>/api/TokenAuth/AuthenticateContent-Type: application/json{ "userNameOrEmailAddress": "api-user", "password": "<password>" } -
The response contains the access token in the field
result.accessToken. -
Send the token in the header of every further request:
Authorization: Bearer <accessToken>
When the token expires, log in again.
Personal access token (PAT)
Section titled “Personal access token (PAT)”A personal access token belongs to exactly one user. An application that uses it acts with the permissions of this user without knowing their password.
Creating a PAT
Section titled “Creating a PAT”You create a PAT through the API, logged in as the user who should own the token:
-
Log in as this user (for example as above with user name and password, or in the Swagger UI).
-
Call
POST /api/services/app/Authentication/CreatePersonalAccessTokenand specify until when the token should be valid:POST https://<server>/api/services/app/Authentication/CreatePersonalAccessTokenAuthorization: Bearer <accessToken>Content-Type: application/json{ "validUntil": "2027-10-31T00:00:00Z" }If you omit
validUntil, the token is valid for one year. invoiceR rejects a date in the past. -
The response contains the token in plain text. Store it immediately in a safe place, for example in a password vault or in the configuration of the application.
Using a PAT
Section titled “Using a PAT”Send the token with every request in the Authorization header with the prefix PAT:
GET https://<server>/api/services/app/Session/GetCurrentLoginInformationsAuthorization: PAT <token>invoiceR rejects the token if it has expired or if the user or the tenant is deactivated or deleted. Replace an expired token with a new one.
