UC-010 — Bulk Email Campaign to Your Contact Lists
- Goal
- Create and send an email campaign to your contact lists, with the price up front and the opens and clicks afterwards
- Channel
- Estimated time
- 20 minutes
Real-world scenarios
- ShopItalia — Black Friday newsletter: The promotion goes to the 10,000 customers of the newsletter list, each greeted by name, on Friday morning at 08:00.
- Studio Dentistico Bianchi — Monthly newsletter: Once a month the practice sends prevention tips and the opening hours to the list of its patients.
- AcquaLuce Energia — New customer area: An announcement to all customers with a button to the new portal, and the clicks counted to see how many opened it.
Prerequisites
Before you begin, make sure you have:
- Active API Key with the
CAMPAIGNSoperation → How to get one - Sufficient credit → The price check of Step 3 tells whether your wallet covers the campaign
- Verified email sender → An address or a domain verified in the Qlara platform, under Email Marketing › Settings › Addresses: senders cannot be added through the API
- Contact list created and populated → See UC-011. Its contacts need an email address (
emailAddresses) and the email marketing consent,email_status: OPTINin theirconsents
Nothing is sent and no credit is reserved until you confirm the campaign (Step 4): you can create, change and price a draft freely.
Campaign lifecycle
The diagram shows the main statuses. A campaign is a draft (CREATED) until you confirm it; the confirmation reserves the price and starts the content checks (VALIDATING). When they pass, the campaign waits for its start in PRE_BILLED, then goes through the sending statuses (READY, EXPLODING, EXPLODED, BILLED, STARTED, SENT) up to ENDED. With a new sender it may first wait for an operator review (HUMAN_REVIEW). When the checks fail it moves to REJECTED or QUARANTINE and the reserved credit is released: fix the campaign and confirm it again.
Step 1 — Pick the sender
List the senders your account can send email campaigns from.
curl -X GET https://api.qlara.ai/api/partner-gateway/campaigns/email/senders \
-H "X-Api-Key: YOUR_API_KEY"
Response — Your senders
[
{
"type": "DOMAIN",
"id": 12,
"fromNameId": 31,
"from": "news@shopitalia.example",
"displayName": "ShopItalia News",
"isDefault": true,
"status": "VERIFIED"
},
{
"type": "DOMAIN",
"id": 12,
"fromNameId": 30,
"from": "info@shopitalia.example",
"displayName": "ShopItalia",
"isDefault": false,
"status": "VERIFIED"
}
]
A verified domain appears once per From Name (here two, on the domain with id 12); a single verified address appears once, with type EMAIL. Only a sender in status VERIFIED can be used. Take its type, id and, for a domain, fromNameId: they go into the campaign as emailSenderType, emailSenderId and emailSenderFromNameId.
Step 2 — Create the campaign (draft)
Create the campaign with the sender of Step 1, the recipients and the content. destinationType: 0 sends to the contacts of contactListIds. The content is a subject and exactly one of bodyHtml and templateId; placeholders in single braces, such as {firstName}, are replaced with each contact's fields.
curl -X POST https://api.qlara.ai/api/partner-gateway/campaigns/email \
-H "Content-Type: application/json" \
-H "X-Api-Key: YOUR_API_KEY" \
-d '{
"name": "Black Friday 2027",
"description": "Newsletter Black Friday - sconto 30% su tutto il catalogo",
"emailSenderType": "DOMAIN",
"emailSenderId": 12,
"emailSenderFromNameId": 31,
"destinationType": 0,
"contactListIds": [87],
"subject": "{firstName}, il Black Friday inizia adesso: -30% su tutto",
"bodyHtml": "<html><body><p>Ciao {firstName},</p><p>Fino al 28/11: -30% su tutto con il codice <strong>BF2027</strong>.</p><p><a href=\"https://shop.example.it/bf\">Scopri le offerte</a></p><p><a id=\"unsubscribe\" href=\"#\">Disiscriviti</a></p></body></html>"
}'
The bodyHtml of this request, on several lines for reading. It greets each contact by name and ends with the link that Step 4 turns into the unsubscribe link:
<html>
<body>
<p>Ciao {firstName},</p>
<p>Fino al 28/11: -30% su tutto con il codice <strong>BF2027</strong>.</p>
<p><a href="https://shop.example.it/bf">Scopri le offerte</a></p>
<p><a id="unsubscribe" href="#">Disiscriviti</a></p>
</body>
</html>
Response — Campaign created
201 Created, with the campaign as it was saved. Its main fields:
{
"id": 3120,
"name": "Black Friday 2027",
"description": "Newsletter Black Friday - sconto 30% su tutto il catalogo",
"status": "CREATED",
"emailSenderType": "DOMAIN",
"emailSenderId": 12,
"emailSenderFromNameId": 31,
"destinationType": 0,
"contactListIds": [87],
"subject": "{firstName}, il Black Friday inizia adesso: -30% su tutto",
"creationDate": "2027-11-26 06:50:00.000+0000"
}
The id field is the identifier you will use in all subsequent steps. Email campaigns have endpoints of their own, under /campaigns/email: GET /campaigns does not list them.
Step 3 — Check the price
Count the recipients the campaign has now and price them, before confirming.
curl -X GET \
https://api.qlara.ai/api/partner-gateway/campaigns/email/3120/price \
-H "X-Api-Key: YOUR_API_KEY"
Response — Price preview
{
"totalDestinations": 10000,
"effectiveDestinations": 9412,
"totalPrice": 94120,
"availableCredit": 500000,
"hasEnoughCredit": true,
"walletKind": "EMAIL",
"exclusions": {
"missingEmail": 310,
"invalidEmailFormat": 24,
"noMarketingConsent": 233,
"hardBounce": 21,
"spamRisk": 12
}
}
Of the 10,000 contacts of the list (totalDestinations), 9,412 will receive the email and are charged (effectiveDestinations). totalPrice is their price and availableCredit your balance, both in the smallest unit of the wallet named by walletKind.
exclusions counts the contacts left out, by reason: 310 have no email address, 24 an address that is not valid, 233 have not given the email marketing consent and 21 bounced permanently before. The 12 addresses of spamRisk are at risk of spam complaints: they still receive the email and are counted in effectiveDestinations.
Nothing is reserved by this call: the confirmation counts and prices the recipients again.
When hasEnoughCredit is false, the confirmation answers 402. Top up your credit before proceeding.
Step 4 — Confirm and start sending
Confirm the draft. The body is optional: unsubscribeLinkId is the id attribute of the link of your bodyHtml that becomes the unsubscribe link, here <a id="unsubscribe">.
curl -X PUT \
https://api.qlara.ai/api/partner-gateway/campaigns/email/3120/confirm \
-H "Content-Type: application/json" \
-H "X-Api-Key: YOUR_API_KEY" \
-d '{
"unsubscribeLinkId": "unsubscribe"
}'
Every email carries an unsubscribe link: without unsubscribeLinkId, or when no link has that id, a standard one is added at the end of the email.
Response — Campaign confirmed
202 Accepted: the recipients are counted, the price is reserved on your wallet and the content checks start (status VALIDATING). The answer carries no campaign data: follow the campaign as in Step 5. Since this campaign has no scheduledDate, it is sent as soon as the checks pass.
Variant — Scheduled send
To send at a given time, set scheduledDate (format yyyy-MM-dd HH:mm:ss.SSSZ, in the future) when you create the campaign, or on the draft before confirming it. An update changes only the fields you send:
curl -X PUT https://api.qlara.ai/api/partner-gateway/campaigns/email/3120 \
-H "Content-Type: application/json" \
-H "X-Api-Key: YOUR_API_KEY" \
-d '{
"scheduledDate": "2027-11-26 08:00:00.000+0100"
}'
Then confirm it as above: once the checks pass, the campaign waits in PRE_BILLED and is sent at the scheduled date.
Every update moves the campaign back to CREATED: a confirmed one gets its reserved credit back and must be confirmed again. A confirmed campaign (PRE_BILLED) can be changed only while its scheduledDate is still outside the platform's edit window, the minutes before the start in which a campaign can no longer change; one confirmed without scheduledDate can no longer be changed.
Step 5 — Follow the campaign
Read the status and the counters during and after sending.
curl -X GET https://api.qlara.ai/api/partner-gateway/campaigns/email/3120 \
-H "X-Api-Key: YOUR_API_KEY"
Response — Campaign completed
The main fields:
{
"id": 3120,
"name": "Black Friday 2027",
"status": "ENDED",
"startDate": "2027-11-26 07:00:04.000+0000",
"endDate": "2027-11-26 07:21:30.000+0000",
"totalDestinations": 9412,
"totalPrice": 94120,
"totalSent": 9412,
"totalSuccess": 9371,
"totalFailed": 41,
"totalRead": 4310,
"totalReadUnique": 3122,
"totalClick": 1206,
"totalClickUnique": 874
}
Final result: 9,371 emails sent successfully (totalSuccess) out of 9,412 (totalSent). 3,122 were opened at least once (totalReadUnique, 33.3% of those sent successfully) and 874 had at least one click (totalClickUnique, 9.3%). totalDestinations and totalPrice are the ones set at confirmation.
Variants
Send to addresses written in the request
With destinationType: 1 the campaign goes to the addresses listed in destinations, without a contact list. In the request of Step 2 they take the place of destinationType: 0 and contactListIds:
{
"destinationType": 1,
"destinations": ["giulia.rossi@example.it", "m.bianchi@example.it"]
}
Use an email template
Instead of bodyHtml, pass the templateId of an email template of your account together with its templateLocale (for example it). The two are alternatives: a request with both, or with neither, answers 400.
Attach files
attachments adds files of your media library to every email, each by its mediaKey: see UC-021 — Upload and Manage Media.
Common errors
400 Bad Request — Body not valid
{
"status": "fail",
"data": [["Exactly one of 'templateId' and 'bodyHtml' is required"]]
}
Solution: data lists the checks that failed. A campaign needs a name, the sender, a subject and exactly one of bodyHtml and templateId; with destinationType 0 also contactListIds, with 1 destinations.
404 Not Found — Sender not verified
{
"status": "fail",
"data": "Email sender not found among the VERIFIED senders of your account"
}
Solution: POST /campaigns/email and PUT /campaigns/email/{id} answer this way when emailSenderId and emailSenderType do not match a VERIFIED sender of your account, or emailSenderFromNameId is not a From Name of that domain. The campaign is not created or changed. Take the three values from GET /campaigns/email/senders (Step 1).
402 Payment Required — Insufficient credit
{
"status": "fail",
"data": "Insufficient credit for the email campaign"
}
Solution: PUT /campaigns/email/{id}/confirm answers this way when your wallet does not cover the price of the campaign. Check hasEnoughCredit with the price call (Step 3), top up your credit and confirm again.
400 Bad Request — Campaign not in draft
{
"status": "fail",
"data": "Only a draft email campaign (status CREATED) can be confirmed"
}
Solution: only a campaign in status CREATED can be confirmed. One that is REJECTED or QUARANTINE goes back to CREATED with an update (PUT /campaigns/email/{id}); then confirm it again.
Status REJECTED or QUARANTINE — Content checks failed
The confirmation answered 202, but the content checks did not pass and the reserved credit was released. Read contentAnalysis in GET /campaigns/email/{id}: it has one entry per check, and one of them says whether the body has an unsubscribe link. Fix the campaign with PUT /campaigns/email/{id} and confirm it again.
Expected result
| Step | Action | Result |
|---|---|---|
| 1 | GET /campaigns/email/senders | A VERIFIED sender: type, id and fromNameId |
| 2 | POST /campaigns/email | Campaign in CREATED status, id returned |
| 3 | GET /campaigns/email/{id}/price | effectiveDestinations, totalPrice and hasEnoughCredit |
| 4 | PUT /campaigns/email/{id}/confirm | 202 Accepted, the checks start, then the sending |
| 5 | GET /campaigns/email/{id} | Status ENDED, counters of sent, opened and clicked emails |
Next steps
- UC-011 — Manage Contacts and Lists: Create and populate the contact lists for your campaigns
- UC-014 — Compliance and Opt-out (GDPR): Handle the contacts who opt out
- Email campaigns guide: The endpoints of an email campaign, with updates and deletion
- Email: Send one email to one recipient, without a campaign