Skip to main content

UC-020 — API Key Management

Real-world scenarios​

  • Developer onboarding: The team lead creates a dedicated API Key for a new integration, scoped to only the operations that integration needs.
  • Periodic key rotation: FinSecure rotates its API Keys every 90 days as required by internal security policy.
  • Revoke a compromised key: A developer accidentally committed an API Key to a public repository and needs to revoke it at once, knowing that the messaging endpoints can keep accepting it for up to 24 hours (see Step 4).

Management flow​

The diagram shows the complete API Key lifecycle: scope check, creation, listing and revocation.

Prerequisites​

  • Active account on the Qlara platform
  • At least one existing API Key to authenticate management calls
  • The calling key must be authorized for the AUTHENTICATION operation

Step 1 — Check what your current key can do​

Before creating a key, inspect the one you are calling with. A new key can only be granted operations the calling key already holds, so this tells you the maximum scope available to you.

curl -X GET https://api.qlara.ai/api/partner-gateway/authentication/me \
-H "X-Api-Key: YOUR_API_KEY"

Response — Current key​

{
"id": 1,
"companyId": 100,
"userId": 42,
"username": "api-user",
"trafficType": 0,
"operations": ["AUTHENTICATION", "SMS", "RCS", "WHATSAPP"],
"creationDate": "2025-03-10 14:30:00.000+0100",
"lastUpdateDate": "2025-03-10 14:30:00.000+0100"
}
The key is never sent in the URL

The key is read from the X-Api-Key header, so this endpoint takes no parameters and never echoes the key value back. It replaces the removed GET /authentication/{value}, which took a raw key in the URL.

Step 2 — Create a new API Key​

Call the creation endpoint to generate a new key.

curl -X POST https://api.qlara.ai/api/partner-gateway/authentication \
-H "Content-Type: application/json" \
-H "X-Api-Key: YOUR_API_KEY" \
-d '{
"userId": 4618,
"trafficType": 0,
"operations": ["SMS", "RCS", "WHATSAPP"]
}'
FieldRequiredDescription
userIdYesID of the user the key belongs to, normally the integration owner. It must be a member of your team who has accepted the invitation, the calling key's own userId included: a user of another company, a pending invitation or a suspended member gets 400.
operationsYesOperations the key may call on the Qlara Platform endpoints (/api/partner-gateway): each one opens the endpoints under the path of the same name. Must be a non-empty subset of the operations held by the calling key.
trafficTypeNoTraffic type identifier (0 = standard, the default). A key can grant only 0 or its own traffic type: any other value gets 403. Leave at 0 unless instructed otherwise.

Allowed values for operations, with the Qlara Platform endpoints each one opens:

OperationOpensWhat is there
AUTHENTICATION/authenticationAPI Keys: this use case
CAMPAIGNS/campaignsCampaigns: create, update, price, confirm, statistics
CONTACTS/contactsContacts, contact lists and imports
EXPORTS/exportsExports of delivery reports and contacts
INBOX/inboxConversations: read, reply, assign, archive
MEDIA/mediaMedia gallery: upload, list, delete
MESSAGES/messagesDelivery status, message history and its export
RCS/rcsRCS agents and status of RCS messages
SMS/smsSMS senders
SOCIALS/socialsConnected social profiles
SUBSCRIPTION/subscriptionSubscription and credit
WEBHOOKS/webhooksDelivery-status webhook
WHATSAPP/whatsappWhatsApp Business numbers and status of WhatsApp messages
AUTOMATION, CALENDAR, EMAIL, REPORT—No endpoint
Operations do not restrict sending

Operations scope only the Qlara Platform endpoints (/api/partner-gateway), where a call outside the key's operations gets 401. The messaging endpoints (/api/message-server) and media downloads (/api/files) accept any key of your account, whatever its operations: every key you hand out can send SMS, RCS, WhatsApp and email messages and spend credit. A key is therefore no isolation boundary for sending. See Operations and revocation.

Response — Key created​

{
"id": 3,
"companyId": 100,
"userId": 4618,
"apiKey": "Ab3dK7pQ2vLx9mRt4sNw8yZc1bHf6jDg0eUa5iOWx9z",
"username": null,
"trafficType": 0,
"operations": ["SMS", "RCS", "WHATSAPP"],
"creationDate": "2026-02-02 10:15:00.000+0100",
"lastUpdateDate": "2026-02-02 10:15:00.000+0100"
}
Save the key immediately

The apiKey field is shown only at creation time. Copy it and store it in a secret manager (e.g. Vault, AWS Secrets Manager). It cannot be retrieved again through any endpoint.

No username on creation

Keys created here are identified by their id and userId and carry no username, so username in the response is always null. A username sent in the request body is ignored.

Behind the scenes — Key generation and scoping
  1. Authorization: The gateway resolves the calling key and checks it is authorized for the AUTHENTICATION operation.
  2. Scope check: The requested operations are compared against the calling key's own operations. Anything beyond them is refused with 403 — a key cannot grant privileges it does not have. The same holds for a trafficType other than 0 or the calling key's own.
  3. User check: The userId must be an accepted member of your team; otherwise the request is refused with 400.
  4. Generation: A 43-character key string is generated and returned once, in this response only.
  5. Association: The key is linked to the company of the calling key and to the userId you supplied.

Step 3 — List existing keys​

Retrieve the API Keys associated with your account. Add the optional userId query parameter to filter by owner.

curl -X GET https://api.qlara.ai/api/partner-gateway/authentication \
-H "X-Api-Key: YOUR_API_KEY"

Response — Key list​

[
{
"id": 1,
"companyId": 100,
"userId": 42,
"apiKey": "Kf8t***********************************Qe4n",
"username": "api-user",
"trafficType": 0,
"operations": ["AUTHENTICATION", "SMS", "RCS", "WHATSAPP"],
"creationDate": "2025-03-10 14:30:00.000+0100",
"lastUpdateDate": "2025-03-10 14:30:00.000+0100"
},
{
"id": 2,
"companyId": 100,
"userId": 5172,
"apiKey": "Zq7m***********************************Lp2k",
"username": null,
"trafficType": 0,
"operations": ["SMS", "WHATSAPP"],
"creationDate": "2026-01-15 09:00:00.000+0100",
"lastUpdateDate": "2026-01-15 09:00:00.000+0100"
},
{
"id": 3,
"companyId": 100,
"userId": 4618,
"apiKey": "Ab3d***********************************Wx9z",
"username": null,
"trafficType": 0,
"operations": ["SMS", "RCS", "WHATSAPP"],
"creationDate": "2026-02-02 10:15:00.000+0100",
"lastUpdateDate": "2026-02-02 10:15:00.000+0100"
}
]

The response is a plain array of all your keys, with no pagination: here the calling key (1), an older key (2) and the key created in Step 2 (3). Each key appears masked in apiKey, with only its first and last 4 characters visible, so you can tell your keys apart: the full value is never returned by this endpoint. userId is null on some older keys.

Step 4 — Revoke a compromised key​

Delete a key that should no longer be used. The key id goes in the path: here key 2.

curl -X DELETE https://api.qlara.ai/api/partner-gateway/authentication/2 \
-H "X-Api-Key: YOUR_API_KEY"

Response — Key revoked​

204 No Content — the response has no body. A key that does not exist, or belongs to another account, returns 404. A key that holds an operation the calling key does not hold returns 403.

Behind the scenes — What happens after revocation
  1. Immediate invalidation on the Qlara Platform: The key is removed from the Key Store, and from then on requests to the Qlara Platform endpoints (/api/partner-gateway) that use it receive 401 Unauthorized. The messaging endpoints (/api/message-server) and /api/files keep a cached copy of the keys they have checked, so they can keep accepting the deleted key, and sending messages with it, for up to 24 hours. To cut off a leaked key, revoke it, treat it as still live on those endpoints for up to a day, and contact Qlara support.
  2. No rollback: Deletion is irreversible. To restore access, create a new key.
  3. Which keys you can delete: A key can delete itself and any key of your account whose operations are all among its own, with or without a userId: here key 1 holds both operations of key 2. When the key to delete holds an operation that the calling key does not hold, the answer is 403 and nothing is deleted.

Expected result​

StepActionResult
1GET /authentication/me200 OK with the calling key's operations
2POST /authentication201 Created, full apiKey returned once
3GET /authentication200 OK with the array of keys (masked key values, first and last 4 characters visible)
4DELETE /authentication/{id}204 No Content

Complete end-to-end example​

Scenario FinSecure: quarterly key rotation.

BASE=https://api.qlara.ai/api/partner-gateway

# 1. Read the calling key: its id (the key to retire) and the scope it can grant
ME=$(curl -s -X GET "$BASE/authentication/me" -H "X-Api-Key: $CURRENT_KEY")
OLD_KEY_ID=$(echo "$ME" | jq -r '.id')
echo "$ME" | jq '.operations'

# 2. Create the new key, scoped to the same operations: AUTHENTICATION lets it revoke the old one
NEW_KEY=$(curl -s -X POST "$BASE/authentication" \
-H "Content-Type: application/json" \
-H "X-Api-Key: $CURRENT_KEY" \
-d '{
"userId": 4618,
"trafficType": 0,
"operations": ["AUTHENTICATION", "SMS", "RCS", "WHATSAPP"]
}' | jq -r '.apiKey')

echo "New key: $NEW_KEY"

# 3. Verify the new key works and inspect its scope
curl -s -X GET "$BASE/authentication/me" \
-H "X-Api-Key: $NEW_KEY" | jq '{id, operations}'

# 4. Revoke the old key by its id
curl -s -o /dev/null -w "%{http_code}\n" \
-X DELETE "$BASE/authentication/$OLD_KEY_ID" \
-H "X-Api-Key: $NEW_KEY"

Variants​

Create a least-privilege key per integration​

Scope each key to the smallest set of operations that covers its job on the Qlara Platform endpoints. This limits what the key can read and change there, not what it can send: any key of your account can send through the messaging endpoints and spend credit, whatever its operations.

# Key that can only list the SMS senders (GET /sms/senders)
curl -X POST https://api.qlara.ai/api/partner-gateway/authentication \
-H "Content-Type: application/json" \
-H "X-Api-Key: YOUR_API_KEY" \
-d '{"userId": 4618, "operations": ["SMS"]}'

# Marketing automation key
curl -X POST https://api.qlara.ai/api/partner-gateway/authentication \
-H "Content-Type: application/json" \
-H "X-Api-Key: YOUR_API_KEY" \
-d '{"userId": 4618, "operations": ["CONTACTS", "CAMPAIGNS", "MESSAGES"]}'

Common errors​

400 Bad Request — Missing or empty operations​

{
"status": "fail",
"data": [
["operations is required: a key with no operations cannot call any /api/partner-gateway endpoint"]
]
}

Solution: Send a non-empty operations array. A key with no operations cannot call any Qlara Platform endpoint. A missing userId is reported the same way, with the message userId is required.

400 Bad Request — userId not in your team​

{
"status": "fail",
"data": "userId is not a user of your company"
}

Solution: Use the id of a member of your team who has accepted the invitation. A user of another company, a pending invitation or a suspended member is refused, and so is the calling key's own userId if it is not such a member.

401 Unauthorized — Invalid key​

{
"error": "Invalid API Key"
}

Solution: Verify that the X-Api-Key header is present and that the key used to manage other keys is still active and authorized for the AUTHENTICATION operation.

403 Forbidden — Requested operations exceed your scope​

{
"status": "fail",
"data": "Cannot grant operations beyond the caller's own scope: [CAMPAIGNS]"
}

Solution: A key cannot grant privileges it does not have: data lists the operations refused. Call GET /authentication/me to see what the calling key holds, then request a subset of those operations. A trafficType other than 0 or the calling key's own is refused the same way, with Cannot grant a traffic type other than 0 or the caller's own: followed by the value.

404 Not Found — Key does not exist​

Solution: No key with that id exists in your account: it does not exist, or it belongs to another company. Check the id in the path against the list returned by GET /authentication.

Next steps​

References​