Skip to main content

Authentication

The Quantaprice API uses OAuth 2.0 with API keys. You exchange your API key for an access token, and then use the token to call the API.

Creating an API key​

  1. Sign in to your tenant console at https://YOUR_TENANT.quantaprice.com.
  2. Open Settings → API Keys.
  3. Click Create API Key.
  4. Enter a descriptive name for the key, such as "Production Server" or "Development".
  5. Choose the key's permissions. Give it only what the integration needs; see Key permissions.
  6. Click Create.
Store your secret securely

The client_secret is shown only once, when the key is created. Copy it immediately and store it securely. If you lose the secret, you need to create a new API key.

API key components​

When you create an API key, you receive two values:

ComponentDescriptionExample
client_id24-character hexadecimal identifiera1b2c3d4e5f6a1b2c3d4e5f6
client_secret64-character hexadecimal secret0123456789abcdef...

The client_id is always visible in the console. The client_secret is shown only once, when the key is created.

Key permissions​

A key can do only what its permissions allow. Its access tokens carry the permissions in the scope claim. Taking and restoring backups and purging data are available only to people signed in to the console, whatever permissions a key holds.

PermissionWhat it allows
price:readRead and query prices
price:writeCreate, change and delete prices
article:readRead articles, bundle rules and article tax classes
article:writeCreate, change and delete articles, bundle rules and article tax classes
pricelist:readRead and search pricelists
pricelist:writeCreate, change and delete pricelists
settings:readRead configuration, currencies, VAT, FX rates, rounding and webhooks, and the combined change log (GET /changelog)
settings:writeChange configuration, currencies, VAT, FX rates, rounding and webhooks

A write permission does not include the matching read permission. A catalogue import that also reads back what it wrote needs both. A price display needs price:read; a catalogue import needs article:write, pricelist:write and price:write.

You can give a key only the permissions you hold yourself. Creating, changing, revoking and deleting keys requires apikey:write, and viewing them requires apikey:read. Owners and admins hold both. See Users and sign-in.

You can change the permissions of an existing key at any time, without replacing it. See Changing a key's permissions.

Authentication flow​

Step 1: Exchange your API key for an access token​

Use the OAuth 2.0 client_credentials grant to exchange your API key for a JWT access token:

bash
curl -X POST "https://login.quantaprice.com/oauth2/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_id=your_client_id" \
-d "client_secret=your_client_secret"

Response:

json
{
"access_token": "eyJhbGciOiJSUzI1NiIs...",
"token_type": "Bearer",
"expires_in": 900
}

The access token is valid for 15 minutes (900 seconds).

Step 2: Call the API with the access token​

Send the access token in the Authorization header:

bash
curl -X GET "https://YOUR_TENANT.quantaprice.com/api/price/SKU-PRODUCT-001/your-pricelist" \
-H "Authorization: Bearer eyJhbGciOiJSUzI1NiIs..." \
-H "Content-Type: application/json"

Checking a token​

GET /user/whoami returns who a token identifies and what it is allowed to do:

bash
curl "https://YOUR_TENANT.quantaprice.com/api/user/whoami" \
-H "Authorization: Bearer eyJhbGciOiJSUzI1NiIs..."
json
{
"authenticated": true,
"tenant": "acme",
"user_id": "a1b2c3d4e5f6a1b2c3d4e5f6",
"email": null,
"scopes": ["price:read"],
"scopes_enforced": true,
"quantaprice_admin": false
}

For an API key, user_id is the key's client_id. scopes lists the token's permissions. scopes_enforced is always true: every tenant checks permissions on every request.

Code examples​

JavaScript/TypeScript​

typescript
const CLIENT_ID = process.env.QUANTAPRICE_CLIENT_ID;
const CLIENT_SECRET = process.env.QUANTAPRICE_CLIENT_SECRET;
const TOKEN_URL = "https://login.quantaprice.com/oauth2/token";
const API_URL = "https://YOUR_TENANT.quantaprice.com/api";

// Cache for access token
let accessToken: string | null = null;
let tokenExpires = 0;

async function getAccessToken(): Promise<string> {
// Return cached token if still valid (with 60s buffer)
if (accessToken && Date.now() < tokenExpires - 60000) {
return accessToken;
}

const response = await fetch(TOKEN_URL, {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: new URLSearchParams({
grant_type: "client_credentials",
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET
})
});

if (!response.ok) {
throw new Error(`Token request failed: ${response.status}`);
}

const data = await response.json();
accessToken = data.access_token;
tokenExpires = Date.now() + (data.expires_in * 1000);

return accessToken;
}

async function getPrices(sku: string) {
const token = await getAccessToken();

const response = await fetch(`${API_URL}/price/${sku}/your-pricelist`, {
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json"
}
});

return response.json();
}

Python​

python
import os
import time
import requests

CLIENT_ID = os.environ.get("QUANTAPRICE_CLIENT_ID")
CLIENT_SECRET = os.environ.get("QUANTAPRICE_CLIENT_SECRET")
TOKEN_URL = "https://login.quantaprice.com/oauth2/token"
API_URL = "https://YOUR_TENANT.quantaprice.com/api"

# Token cache
_access_token = None
_token_expires = 0

def get_access_token():
global _access_token, _token_expires

# Return cached token if still valid (with 60s buffer)
if _access_token and time.time() < _token_expires - 60:
return _access_token

response = requests.post(TOKEN_URL, data={
"grant_type": "client_credentials",
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET
})
response.raise_for_status()

data = response.json()
_access_token = data["access_token"]
_token_expires = time.time() + data["expires_in"]

return _access_token

def get_prices(sku):
token = get_access_token()

response = requests.get(
f"{API_URL}/price/{sku}/your-pricelist",
headers={
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
)
response.raise_for_status()

return response.json()

Token refresh​

Access tokens expire after 15 minutes. Your application should:

  1. Cache the token. Do not request a new token for every API call.
  2. Track its expiry. Store the expires_in value and request a new token before the current one expires.
  3. Handle 401 responses. If you receive a 401, request a new token and retry.

Managing API keys​

Viewing keys​

Settings → API Keys lists every API key for your tenant, with the time each key was last used to obtain an access token. The client_secret is never displayed after the key is created.

Changing a key's permissions​

To change what an active key may do:

  1. Go to Settings → API Keys.
  2. Find the key and click Edit scopes.
  3. Select the permissions the integration needs, and click Save.

The key keeps its client_id and client_secret, so the integration needs no change. The next access token it obtains carries the new permissions. A token it already holds keeps the old permissions until it expires, within 15 minutes. To stop a key at once, revoke it.

The same rules apply as when you create a key: you can add only permissions you hold yourself. A permission the key already has can stay, or be removed, even if you do not hold it. A revoked key cannot be changed. The audit log records each change as apikey.scopes_changed, with the permissions before and after.

Revoking keys​

To revoke an API key:

  1. Open Settings → API Keys in the console.
  2. Find the key you want to revoke.
  3. Click Revoke.
  4. Confirm.

A revoked key can no longer obtain access tokens. Tokens already issued with it remain valid until they expire, which is within 15 minutes. A revoked key stays in the list, but its name becomes available again: you can create a new key with the same name.

Revoking a key from your integration​

An integration can revoke the key it holds without anyone signing in: it sends the key's own client_id and client_secret, as it does for a token. Use this when the integration is uninstalled or disconnected and should leave no usable key behind. A key can revoke only itself.

bash
curl -X POST "https://login.quantaprice.com/oauth2/revoke" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "client_id=your_client_id" \
-d "client_secret=your_client_secret"

Response:

json
{
"success": true
}
Status codeMeaning
200 OKThe key is revoked. Revoking a key that is already revoked also answers 200, so the call is safe to retry.
400 Bad Requestclient_id or client_secret is missing.
401 UnauthorizedWrong secret or unknown client_id, answered with invalid_client as at the token endpoint. Nothing changed.
429 Too Many RequestsRate limited, like the token endpoint. Retry after the time given.
503 Service UnavailableThe key could not be revoked right now. Nothing changed; retry shortly.

The key then shows as revoked under Settings → API Keys, and the audit log records apikey.revoked with the key itself as the actor. As with any revocation, tokens already issued remain valid until they expire, within 15 minutes.

Deleting keys​

You can delete an API key permanently, whether it is active or revoked:

  1. Open Settings → API Keys in the console.
  2. Find the key you want to delete.
  3. Click Delete.
  4. Confirm.

A deleted key can no longer obtain access tokens and is removed from the list. Tokens already issued with it remain valid until they expire, which is within 15 minutes. Deleting a key requires apikey:write.

Security best practices​

  • Never commit API keys to version control. Use environment variables or a secrets manager.
  • Use separate keys for different environments. Create distinct keys for development, staging, and production.
  • Rotate keys periodically. Create a new key, update your applications, then revoke the old key.
  • Grant only what the integration needs. When an integration needs more, change the key's permissions rather than giving a new key every permission.
  • Revoke unused keys. Remove keys that are no longer needed.
  • Monitor key usage. Check "Last used" in Settings → API Keys to find inactive keys. It shows when the key last obtained an access token, not when a token was last used to call the API.
  • Cache tokens. Request a new token only when you need one, not on every API call.

Error responses​

Status codeDescription
401 UnauthorizedInvalid API key, expired token, or missing Authorization header
403 ForbiddenThe token is valid, but its permissions do not cover the request

A token request with an invalid key returns:

json
{
"error": "invalid_client",
"error_description": "Invalid client credentials"
}

A request that the token's permissions do not cover returns 403, with the permission it needs:

json
{
"timestamp": "2026-10-31T12:00:00.000Z",
"status": 403,
"error": "Forbidden",
"message": "Missing required scope: article:write"
}

Give the integration a key that holds that permission.

See also​