Skip to main content

How API Authentication and Authorization Works

Authorize NikoHealth API requests with OAuth 2.0 Client Credentials: get an access token, then send it with every call.

All NikoHealth API requests must be authorized using OAuth 2.0 with the Client Credentials flow. You exchange your Client ID and Client Secret for an access token, then send that token with every API call.


Your Credentials

Your Client ID and Client Secret are provided with your API subscription.

🔒 Keep these secret. Never embed or expose them in HTML, JavaScript or any public-facing application. Use them only in code that runs in a trusted, controlled environment and connects directly to the NikoHealth APIs.


Step 1: Request an Access Token

POST https://{yourDomain}.nikohealth.com/api/identity/connect/token

Headers

Header

Value

Content-Type

application/x-www-form-urlencoded

Form Parameters

Parameter

Value

grant_type

client_credentials

client_id

Your Client ID

client_secret

Your Client Secret

scope

external

Example

curl --location 'https://{yourDomain}.nikohealth.com/api/identity/connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id=YOUR_CLIENT_ID' \
--data-urlencode 'client_secret=YOUR_CLIENT_SECRET' \
--data-urlencode 'scope=external'

Response: 200 OK

{
"access_token": "BE55CF536EC46D12F9FDBF1EFD831E086B121939B9806DF43F3A6043C67DB0AC",
"expires_in": 1200,
"token_type": "Bearer",
"scope": "external"
}

Field

Description

access_token

The token you send with every API request

expires_in

The token lifetime in seconds. 1200 is 20 minutes.

token_type

Always Bearer

scope

external

⏱️ Tokens expire after 20 minutes, and there’s no refresh token. Cache the token and reuse it for all requests until shortly before it expires, then request a new one. Don’t request a new token for every API call.


Step 2: Call the API

Pass the access token as a Bearer token in the Authorization header of every request.

Base URL: https://{yourDomain}.nikohealth.com/api/external

curl --request GET \
--url 'https://{yourDomain}.nikohealth.com/api/external/v1/patients' \
--header 'Authorization: Bearer {access_token}' \
--header 'Accept: application/json'

If the token is missing, expired or invalid, the API returns 401 Unauthorized. Request a new token and retry.


Using Swagger

The Swagger interface you’ve been given lets you try the APIs directly while you build your integration. To authorize in Swagger:

  1. Click the green Authorize button at the top right of the page.

  2. Enter your Client ID in the client_id field.

  3. Enter your Client Secret in the client_secret field.

  4. Under Scopes, check external.

  5. Click Authorize.

Swagger requests and attaches the token for you, so you can call any endpoint from the page.


Common Errors

Code

Meaning

400 (token endpoint)

Invalid request, such as a wrong grant_type, a bad client ID or secret, or a missing scope

401 (API)

The token is missing, expired or invalid

403 (API)

The token is valid, but your client doesn’t have permission for that resource

429

Too many requests

Did this answer your question?