Quick Start
Send your first message in a few minutes, with a campaign: the way every new integration sends SMS, RCS and WhatsApp messages. This page sends one SMS to your own phone.
Prerequisites
- An active Qlara account, with enough credit for one SMS
- An API key (from the settings section of the platform) whose operations include
CAMPAIGNSandSMS - An SMS sender registered in the platform and approved
All the calls below go to https://api.qlara.ai/api/partner-gateway, with the key in the X-Api-Key header.
1. Find your sender
A campaign can send only from an approved sender of your account. List yours:
curl "https://api.qlara.ai/api/partner-gateway/sms/senders" \
-H "X-Api-Key: YOUR_API_KEY"
{
"data": [
{ "sender": "MyCompany", "status": "APPROVED" },
{ "sender": "MyShop", "status": "PENDING" }
],
"totalCount": 2
}
The example shows only the fields you need. Pick a sender whose status is APPROVED and copy it exactly as listed: any other sender is refused with 403.
2. Create the campaign
destinationType: 1 sends to the phone numbers written in destinations, in international format, without creating contacts. Put your own number there.
curl -X POST "https://api.qlara.ai/api/partner-gateway/campaigns" \
-H "X-Api-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "My first campaign",
"sendingMode": "SMS",
"destinationType": 1,
"destinations": ["+393401234567"],
"smsSender": "MyCompany",
"smsBody": "Hello! This is my first message from Qlara.",
"readyToSend": true
}'
The API answers 201 Created with the campaign as stored. Keep its id:
{
"id": 1542,
"name": "My first campaign",
"status": "DRAFT",
"sendingMode": "SMS",
"destinationType": 1,
"destinations": ["+393401234567"],
"smsSender": "MyCompany",
"smsBody": "Hello! This is my first message from Qlara.",
"readyToSend": true
}
Nothing is sent and no credit is used yet: a campaign leaves only when you confirm it. Until then you can change it with PUT /campaigns/{id} and see what it costs with GET /campaigns/{id}/price.
3. Confirm it
curl -X PUT "https://api.qlara.ai/api/partner-gateway/campaigns/1542/confirm" \
-H "X-Api-Key: YOUR_API_KEY"
The request has no body. 202 Accepted, with no body either, means the price was reserved on your credit and the sending is queued: with no scheduledDate, it starts at once. From now on the campaign can no longer be changed.
A campaign that is already confirmed answers 400 to a second confirmation. If the first answer got lost, read the campaign (step 4) before confirming again.
4. Read the result
curl "https://api.qlara.ai/api/partner-gateway/campaigns/1542" \
-H "X-Api-Key: YOUR_API_KEY"
{
"id": 1542,
"name": "My first campaign",
"status": "ENDED",
"sendingMode": "SMS",
"totalDestinations": 1,
"totalSent": 1,
"totalSuccess": 1,
"totalFailed": 0,
"smsSent": 1,
"smsSuccess": 1,
"smsFailed": 0
}
After confirmation status is PRE_BILLED, and it reaches ENDED once every message has been processed. The counters fill in meanwhile: totalSuccess counts the delivered messages. Webhooks do not report the delivery of campaign messages: read it here, or export the outcome of every message (see UC-002).
The whole flow in your language
- Node.js
- Python
- PHP
- Java
const BASE = "https://api.qlara.ai/api/partner-gateway";
const headers = {
"X-Api-Key": process.env.QLARA_API_KEY,
"Content-Type": "application/json",
};
// 1. Create the campaign
const created = await fetch(`${BASE}/campaigns`, {
method: "POST",
headers,
body: JSON.stringify({
name: "My first campaign",
sendingMode: "SMS",
destinationType: 1,
destinations: ["+393401234567"],
smsSender: "MyCompany",
smsBody: "Hello! This is my first message from Qlara.",
readyToSend: true,
}),
});
if (created.status !== 201) throw new Error(`Create failed: ${created.status}`);
const { id } = await created.json();
// 2. Confirm it: 202 means the sending is queued
const confirmed = await fetch(`${BASE}/campaigns/${id}/confirm`, {
method: "PUT",
headers,
});
if (confirmed.status !== 202) throw new Error(`Confirm failed: ${confirmed.status}`);
// 3. Read the result
const campaign = await (await fetch(`${BASE}/campaigns/${id}`, { headers })).json();
console.log(campaign.status, campaign.totalSuccess, campaign.totalFailed);
import os
import requests
BASE = "https://api.qlara.ai/api/partner-gateway"
headers = {"X-Api-Key": os.environ["QLARA_API_KEY"]}
# 1. Create the campaign
created = requests.post(
f"{BASE}/campaigns",
headers=headers,
json={
"name": "My first campaign",
"sendingMode": "SMS",
"destinationType": 1,
"destinations": ["+393401234567"],
"smsSender": "MyCompany",
"smsBody": "Hello! This is my first message from Qlara.",
"readyToSend": True,
},
)
created.raise_for_status()
campaign_id = created.json()["id"]
# 2. Confirm it: 202 means the sending is queued
confirmed = requests.put(f"{BASE}/campaigns/{campaign_id}/confirm", headers=headers)
confirmed.raise_for_status()
# 3. Read the result
campaign = requests.get(f"{BASE}/campaigns/{campaign_id}", headers=headers).json()
print(campaign["status"], campaign.get("totalSuccess"), campaign.get("totalFailed"))
<?php
const BASE = "https://api.qlara.ai/api/partner-gateway";
function call(string $method, string $path, ?array $body = null): array
{
$ch = curl_init(BASE . $path);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => [
"X-Api-Key: " . getenv("QLARA_API_KEY"),
"Content-Type: application/json",
],
]);
if ($body !== null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
}
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return [$status, json_decode($response, true)];
}
// 1. Create the campaign
[$status, $campaign] = call("POST", "/campaigns", [
"name" => "My first campaign",
"sendingMode" => "SMS",
"destinationType" => 1,
"destinations" => ["+393401234567"],
"smsSender" => "MyCompany",
"smsBody" => "Hello! This is my first message from Qlara.",
"readyToSend" => true,
]);
if ($status !== 201) {
exit("Create failed: $status\n");
}
$id = $campaign["id"];
// 2. Confirm it: 202 means the sending is queued
[$status] = call("PUT", "/campaigns/$id/confirm");
if ($status !== 202) {
exit("Confirm failed: $status\n");
}
// 3. Read the result
[, $campaign] = call("GET", "/campaigns/$id");
echo $campaign["status"] . "\n";
HttpClient client = HttpClient.newHttpClient();
String base = "https://api.qlara.ai/api/partner-gateway";
String apiKey = System.getenv("QLARA_API_KEY");
// 1. Create the campaign
String body = """
{
"name": "My first campaign",
"sendingMode": "SMS",
"destinationType": 1,
"destinations": ["+393401234567"],
"smsSender": "MyCompany",
"smsBody": "Hello! This is my first message from Qlara.",
"readyToSend": true
}
""";
HttpResponse<String> created = client.send(
HttpRequest.newBuilder()
.uri(URI.create(base + "/campaigns"))
.header("X-Api-Key", apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build(),
HttpResponse.BodyHandlers.ofString());
// Read "id" from created.body() with your JSON library
long id = 1542;
// 2. Confirm it: 202 means the sending is queued
HttpResponse<String> confirmed = client.send(
HttpRequest.newBuilder()
.uri(URI.create(base + "/campaigns/" + id + "/confirm"))
.header("X-Api-Key", apiKey)
.PUT(HttpRequest.BodyPublishers.noBody())
.build(),
HttpResponse.BodyHandlers.ofString());
// 3. Read the result
HttpResponse<String> campaign = client.send(
HttpRequest.newBuilder()
.uri(URI.create(base + "/campaigns/" + id))
.header("X-Api-Key", apiKey)
.GET()
.build(),
HttpResponse.BodyHandlers.ofString());
System.out.println(campaign.body());
If something goes wrong
| Answer | Where | What it means |
|---|---|---|
401 | Any call | The API key is missing or wrong, or its operations do not include CAMPAIGNS (or SMS, for the sender list) |
403 | Create | smsSender is not an approved sender of your account |
400 | Create | A required field is missing, or sendingMode is not a valid value: the body names the field |
400 | Confirm | The campaign has no valid recipient, your credit does not cover its price, or it is already confirmed |
Next steps
- Send to a contact list: with
destinationType: 0andcontactListIdsthe campaign reaches whole lists. See UC-001: Bulk SMS Campaign. - Send on RCS or WhatsApp: these campaigns send a template. See UC-004: Bulk RCS Rich Card Campaign and UC-008: Bulk WhatsApp Template Campaign.
- Add a fallback: a
sendingModesuch asRCS_SMSorWHATSAPP_SMStries the channels from left to right. See the campaigns of RCS and WhatsApp. - Send later: set
scheduledDateon the campaign before you confirm it. - Send an email: email campaigns have endpoints of their own, under
/campaigns/email. See UC-010: Bulk Email Campaign; to send one email to one recipient, see Email. - Send one message to one recipient: without a campaign, use the single sends of SMS, RCS or WhatsApp, one message per call.