Authentication
All API requests require authentication. The methods you can use depend on the endpoint:
- The Qlara Platform endpoints under
/api/partner-gateway/accept only the API Key, in theX-Api-Keyheader. They ignore theAuthorizationheader: a request with Basic credentials and no key gets401with{"error": "Invalid API Key"}. - The messaging endpoints under
/api/message-server/, and the media downloadGET /api/files/{mediaKey}, accept one of the two methods below: the API Key or Basic Auth.
API Key (recommended)
API Key authentication is the simplest and most secure method, and the only one every endpoint accepts. It does not require Base64 encoding and reduces the risk of exposing credentials in logs.
The simplest method. Add the X-Api-Key header to every request. This one lists your campaigns:
- cURL
- Node.js
- Python
- PHP
curl "https://api.qlara.ai/api/partner-gateway/campaigns" \
-H "X-Api-Key: YOUR_API_KEY"
const response = await fetch(
"https://api.qlara.ai/api/partner-gateway/campaigns",
{
headers: {
"X-Api-Key": "YOUR_API_KEY",
},
}
);
const data = await response.json();
console.log(data);
import requests
response = requests.get(
"https://api.qlara.ai/api/partner-gateway/campaigns",
headers={
"X-Api-Key": "YOUR_API_KEY",
},
)
print(response.json())
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => "https://api.qlara.ai/api/partner-gateway/campaigns",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"X-Api-Key: YOUR_API_KEY",
],
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
Never share your API Key in public repositories, client-side code, or insecure channels. If compromised, regenerate it immediately from the Qlara platform.
Your API Key is available in the settings section of the Qlara platform.
Operations and revocation
The operations of an API key scope only the Qlara Platform endpoints: each operation opens the endpoints under the path of the same name (CONTACTS opens /contacts, SMS opens /sms, and so on), and a call outside the key's operations gets 401. The messaging endpoints and /api/files accept any key of your account, whatever its operations: a key limited to a few operations can still send messages and spend credit there. See UC-020 — API Key Management.
Deleting a key with DELETE /api/partner-gateway/authentication/{id} revokes it at once on the Qlara Platform endpoints. The messaging endpoints and /api/files keep a cached copy of the keys they have checked, so they can keep accepting a deleted key for up to 24 hours. If a key was compromised, delete it and also contact Qlara support.
Basic Auth
Standard HTTP method with username and password encoded in Base64. Only the messaging endpoints (/api/message-server/) and /api/files accept it. This one lists your WhatsApp templates:
- cURL
- Node.js
- Python
- PHP
curl "https://api.qlara.ai/api/message-server/whatsapp/templates" \
-H "Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ="
const response = await fetch(
"https://api.qlara.ai/api/message-server/whatsapp/templates",
{
headers: {
Authorization: "Basic " + btoa("username:password"),
},
}
);
const data = await response.json();
console.log(data);
import requests
response = requests.get(
"https://api.qlara.ai/api/message-server/whatsapp/templates",
auth=("username", "password"),
)
print(response.json())
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => "https://api.qlara.ai/api/message-server/whatsapp/templates",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERPWD => "username:password",
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
How to generate the Base64 value
Linux / macOS:
echo -n "username:password" | base64
Windows PowerShell:
[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("username:password"))
IP Whitelist
For each account, a list of allowed IP addresses and ranges can be configured in the Qlara platform. With no list configured, every IP address is allowed.
The list is checked only by the messaging endpoints that send messages, after authentication: the SMS, RCS, WhatsApp and email sends under /api/message-server/. A request from an IP address outside the list gets 511 Network Authentication Required:
{
"status": "error",
"message": "IP address not allowed",
"code": 100
}
The same 511 also comes back if the platform cannot read your account's list at that moment.
The Qlara Platform endpoints under /api/partner-gateway/, and the template, agent and phone-number endpoints of the messaging API, do not check the IP address.
Authentication flow
The Qlara Platform endpoints check only the X-Api-Key header: a missing or unknown key, or one without the operation of the endpoint, gets 401 with {"error": "Invalid API Key"}. The messaging endpoints and /api/files check the credentials in this order:
When an Authorization header is present it is the one checked, and X-Api-Key is ignored: anything other than valid Basic credentials, a Bearer token for example, gets 401 even with a valid key. Do not send the two headers together. Every 401 from these endpoints has an empty body. If the platform cannot check your credentials at that moment, the answer is 502 with an empty body: retry later.
On the messaging endpoints and /api/files, more than 5 failed authentication attempts within 30 seconds block the caller's IP address for 10 minutes, and likewise the Basic Auth username or the API key that failed. On the messaging endpoints, an X-Api-Key value that is not 24 to 64 letters, digits, - or _ gets 401 before it is looked up, and does not count toward the block. While blocked, every request gets 401, even with correct credentials. Stop retrying on 401 and fix the credentials first.
Authentication errors
| Code | Meaning | What to do |
|---|---|---|
401 | Missing or invalid credentials. On the Qlara Platform endpoints, also a key that does not include the operation of the endpoint. On the messaging endpoints and /api/files, also an Authorization header that is not valid Basic Auth, or a caller blocked after repeated failed attempts | Verify your API Key (or your Basic credentials, on the messaging endpoints) and the key's operations; after repeated failures, wait 10 minutes |
403 | The request is not allowed for your key or account, for example POST /api/partner-gateway/authentication asking for operations the calling key does not hold | Request only what your key and account allow |
502 | The messaging endpoints could not check your credentials at that moment | Retry later |
511 | Your IP address is not in your account's list (message sends) | Add the IP address to the list in the Qlara platform |