Campaigns and templates
A campaign sends one message to your lists, to numbers you give it, or both. Use a campaign when you send to more than 500 numbers (the most one message takes), to a list, with each person's own details in the text, or at a later time. Sending a message does none of those: it has no placeholders and no schedule.
Send a campaign
Send the template and who gets it to POST /. The API key needs messages:send:
curl -X POST "https://api.sms.codelia.studio/v1/organizations/$CODELIA_ACCOUNT_ID/messages/campaigns" \
-H "Authorization: Bearer $CODELIA_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: spring-sale-2026" \
-d '{
"from": "InfoSMS",
"body": "Hi {{firstName}}, our spring sale starts Saturday: 20% off everything.",
"recipients": [
{
"to": "+442079460123",
"variables": {
"firstName": "Ada"
}
},
{
"to": "+442079460124",
"variables": {
"firstName": "Grace"
}
}
]
}'const response = await fetch(
`https://api.sms.codelia.studio/v1/organizations/${process.env.CODELIA_ACCOUNT_ID}/messages/campaigns`,
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.CODELIA_API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": "spring-sale-2026",
},
body: JSON.stringify({
"from": "InfoSMS",
"body": "Hi {{firstName}}, our spring sale starts Saturday: 20% off everything.",
"recipients": [
{
"to": "+442079460123",
"variables": {
"firstName": "Ada"
}
},
{
"to": "+442079460124",
"variables": {
"firstName": "Grace"
}
}
]
}),
},
);
console.log(response.status);
console.log(JSON.stringify(await response.json(), null, 2));| Field | What to send |
|---|---|
recipients | Up to 5,000 numbers per request, each { "to": …, "variables": { … }, "language": … }. Only to is required. |
listIds | Up to 25 lists. Send recipients, listIds, or both. |
body or bodies | The template, up to 1,600 characters, or one per language, as when you send a message. |
from | The sender name. Leave it out to use your default. |
scheduledAt | Send later. See Schedule it. |
metadata | Your own keys and text values, kept on the campaign. Keys starting with audience. are refused with reserved_. |
defaults | Fallback values for placeholders, like { "firstName": "there" }. See Placeholders. |
The answer is 202 with the campaign: keep its id. The messages go out in the background.
Once your lists and recipients are put together, the campaign can reach up to 100,000 people; past that, it's refused with too_. A number that is on a list and in recipients gets one message.
Add an Idempotency-Key header, so a retry after a timeout can't send the campaign twice. See Retrying safely.
Placeholders
Write {{firstName}} in the template, and each person gets their own value in its place. Spaces inside the braces are allowed ({{ firstName }}). A name is up to 32 letters, digits and underscores, starts with a letter or an underscore, and is case-sensitive: {{FirstName}} isn't {{firstName}}.
Where the values come from:
- Someone on a list is filled in from their contact:
firstName,lastName,email,birthday, and any key in the contact'smetadata, such as a column from an import. - A number in
recipientsis filled in from its ownvariables, even when a contact has the same number. - A number in
recipientsthat is also on one of the lists takes itsvariableswhen the entry has avariableskey. With novariableskey at all, it's filled in from the contact."variables": {}means no values at all.
A contact's birthday fills {{birthday}} as the day and month, two digits each, like 14/, and never shows the year. If a contact has no birthday set but their metadata has a birthday key, such as a column from an import, the placeholder uses that value. It reads as day/month, like 14/, when it can be read as a date in one of the formats an import reads, and as written otherwise.
To fill in people who have no value, send defaults: one fallback per placeholder name, like { "firstName": "there" }, so Hi {{firstName}} reads Hi there for them. A default is used when a person's value is missing, empty or only spaces, and never replaces a value they have. A default for a placeholder none of your texts use is ignored. Each default is up to 200 characters, and a campaign takes up to 50.
Without a default, a value can be an empty string: its placeholder is replaced with nothing. A missing value fails that person's message with missing_.
When a person's text can't be filled in, their message fails with an errorCode, isn't charged, and everyone else's message still goes out:
errorCode | What happened |
|---|---|
missing_ | The template uses a placeholder this person has no value for. |
unknown_ | Their variables has a key the template doesn't use. Check it for a typo. |
invalid_ | A key in their variables isn't a valid placeholder name. |
value_ | A value is longer than 200 characters. |
rendered_ | The filled-in text is empty. |
rendered_ | The filled-in text, with the unsubscribe line, is longer than 1,600 characters. |
Each person is counted and priced on their own filled-in text, so one long name can put their message into a second part.
Lists
Send to a list by its id in listIds. A smart list reaches whoever matches its filter when the campaign is accepted, or, for a scheduled campaign, when it sends. Creating lists, importing contacts and adding people to a list are on Contacts and lists.
Price it first
POST / takes the same body as POST …/, fills in and prices every person the same way, and never sends or charges. The API key needs messages:read:
curl -X POST "https://api.sms.codelia.studio/v1/organizations/$CODELIA_ACCOUNT_ID/messages/campaigns/quote" \
-H "Authorization: Bearer $CODELIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"from": "InfoSMS",
"body": "Hi {{firstName}}, our spring sale starts Saturday: 20% off everything.",
"recipients": [
{
"to": "+442079460123",
"variables": {
"firstName": "Ada"
}
},
{
"to": "+442079460124",
"variables": {
"firstName": "Grace"
}
}
]
}'const response = await fetch(
`https://api.sms.codelia.studio/v1/organizations/${process.env.CODELIA_ACCOUNT_ID}/messages/campaigns/quote`,
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.CODELIA_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"from": "InfoSMS",
"body": "Hi {{firstName}}, our spring sale starts Saturday: 20% off everything.",
"recipients": [
{
"to": "+442079460123",
"variables": {
"firstName": "Ada"
}
},
{
"to": "+442079460124",
"variables": {
"firstName": "Grace"
}
}
]
}),
},
);
console.log(response.status);
console.log(JSON.stringify(await response.json(), null, 2));The answer has the same shape as pricing a message. People whose text can't be filled in, and numbers that aren't valid or are in a country your sender name or our prices don't cover, are counted in unpriceableCount. Numbers in a country your organization can't send to yet are left out of the price and counted in notAllowedCount. People who opted out and numbers we can't send to are still priced, so sending can cost less than the estimated cost.
How it's charged
The whole estimated cost is taken from your balance once, when the campaign is accepted. If your balance can't cover it, the campaign is refused with 402 and insufficient_, and nothing is sent. A large campaign sent now is accepted shortly after you send it, so a shortfall found then comes back differently: see Large campaigns. A campaign that was accepted never stops halfway for lack of credit.
You get money back for:
- someone who opted out after the campaign was accepted, just before their message was handed to the network;
- messages the network refused to take;
- messages not yet sent when you cancel the campaign;
- messages not yet sent when a transactional campaign stops because your organization's access to transactional messages was turned off.
A message the network took keeps its charge, even if it's never delivered.
Large campaigns
A campaign you send now to more than 500 people, counting each list's members before duplicates are removed, is accepted shortly after the request is answered. The answer is 202 at once, with status queued. Until it's accepted, recipientCount is an estimate that can only go down, and totalEstimatedMicros is 0. Follow it as any campaign, or listen for the campaign.failed webhook.
It's still refused when you send it, as any campaign is, for a problem with the request itself (such as unknown_, unapproved_ or reserved_), for a sending limit your organization has already reached (403, sending_), and when your balance is at or below zero and auto top-up can't add to it (402, insufficient_).
Anything found once it's accepted makes the campaign failed, with a failureReason, and nothing is charged:
- If your balance doesn't cover it, auto top-up is charged once and the campaign waits about 10 minutes for the credit, with
pendingReason: "awaiting_. If the credit hasn't arrived by then, or auto top-up can't be charged, it fails withcredit" insufficient_.credits - If it would pass a sending limit, it fails with
sending_.limit_ reached - If its lists come to more than 100,000 people, it fails with
too_.many_ recipients - If no one is left to send to but numbers we can't send to, it fails with
all_, orrecipients_ unsupported all_if one of them is in a country your organization can't send to yet.recipients_ not_ allowed - If we couldn't process it within an hour, it fails with
processing_.failed
A campaign that failed this way can be sent again, unless it failed with all_ or unknown_.
Follow it
Check a campaign with GET /, where {campaignId} is the id in the answer when you sent it:
curl "https://api.sms.codelia.studio/v1/organizations/$CODELIA_ACCOUNT_ID/messages/campaigns/$CAMPAIGN_ID" \
-H "Authorization: Bearer $CODELIA_API_KEY"const response = await fetch(
`https://api.sms.codelia.studio/v1/organizations/${process.env.CODELIA_ACCOUNT_ID}/messages/campaigns/${process.env.CAMPAIGN_ID}`,
{
headers: {
Authorization: `Bearer ${process.env.CODELIA_API_KEY}`,
},
},
);
console.log(response.status);
console.log(JSON.stringify(await response.json(), null, 2));Poll it while status is queued or sending, or use webhooks to be told when it finishes. The counts:
| Field | What it counts |
|---|---|
recipientCount | Everyone the campaign was for, once lists and recipients are put together. |
sentCount | Messages handed to the network. |
skippedCount | People who weren't sent it because they opted out, their number is one we can't send to, or it's in a country your organization can't send to yet. |
failedCount | Every other message that failed, including people whose text couldn't be filled in. |
deliveredCount | Messages a delivery report had confirmed when the campaign finished. |
While a campaign is sending, the counts go up as each batch of its messages is handed to the network. They're fixed when the campaign finishes. A delivery report that arrives later doesn't change them, or the status. To see what happened to each person, list the campaign's messages with GET /, or follow the message.delivered and message.failed webhook events.
A campaign's status is one of:
status | What it means |
|---|---|
scheduled | Waiting for its time. Nothing is charged yet. |
queued | Waiting to start. Its messages haven't started going out. A campaign sent now to more than 500 people is queued for a short while before it's accepted and charged. |
sending | Its messages are being handed to the network. |
completed | Finished, and every message was handed to the network, apart from people it skipped. It doesn't mean every message was delivered. |
partial_ | Finished, and failedCount is more than 0: some messages were handed over and some failed. |
failed | Nothing was handed to the network. That includes a campaign where everyone opted out: it sends campaign.failed, and nothing is charged. |
cancelled | You canceled it. |
People who opted out, numbers we can't send to (errorCode unsupported_) and numbers in a country your organization can't send to yet (errorCode country_) are counted in skippedCount, not failedCount, so a campaign whose only misses are these is completed. If one of the numbers was either of the last two and no one else is left to send to, the campaign is refused with a 400 when you send or schedule it: all_ if one of the numbers is in such a country, otherwise all_. To send to a country your organization can't send to yet, email hello@codelia.studio. A campaign where everyone opted out finishes failed. A failed placeholder is a failure: it counts in failedCount.
A campaign that couldn't send to anyone says why in failureReason, and nothing is charged for it:
all_: everyone it was for had opted out.recipients_ opted_ out no_: nobody could be sent the message, and at least one person failed for a reason other than opting out. Each person's message has ansendable_ recipients errorCodethat says why.all_orrecipients_ not_ allowed all_: when a scheduled campaign was due, or once a large campaign sent now was accepted, one of its numbers was in a country your organization can't send to yet, or was a number we can't send to, and no one else was left to send to. Any other campaign you send now with such numbers is refused with a 400 instead.recipients_ unsupported - A scheduled campaign that couldn't go out when it was due, or a large campaign sent now that couldn't go out once it was accepted, has a code like
insufficient_,credits unapproved_,sender_ id sender_(it was sent withoutid_ required fromand your organization no longer has a default sender),organization_,suspended sending_,limit_ reached no_,recipients unknown_,list unsupported_(a smart list's filter can't be read),filter default_orvariant_ required too_. A large campaign can also havemany_ recipients processing_, when we couldn't process it within an hour.failed feature_: a scheduled transactional campaign was due, and your organization wasn't approved for transactional messages. Once it is, it can be sent again. See Transactional messages.not_ enabled
One reason is set on a campaign that sent to some people: a transactional campaign stops if your organization's access to transactional messages is turned off while it's sending. It finishes partial_, or failed if nothing had gone yet, with failureReason: "feature_. The messages not yet sent have errorCode campaign_ and are refunded. See If access is turned off while it's sending.
Otherwise failureReason is null: a campaign that sent to anyone records its failures on each message. New reasons can be added, so treat one you don't know as a failure.
A sending campaign with stalled: true stopped part-way. It's picked up again on its own; to send the rest now, call POST /. Nothing is charged again, and nobody who already got the message gets it twice.
Schedule it
Add scheduledAt, between 5 minutes and 90 days ahead, and the campaign is created scheduled:
- Scheduling needs auto top-up, set up in the portal. Without it, the answer is
409withauto_.topup_ required - Nothing is charged when you schedule. The campaign is priced and charged when it sends, at that day's prices, and a smart list reaches whoever matches then.
- If your balance is short when it's due, it tries again every 2 minutes for up to 30 minutes. After that it becomes
failed, withfailureReason: "insufficient_.credits" - If, when it's due, no one is left to send to but numbers we can't send to (and people who opted out), it becomes
failed, withfailureReason: "all_, and nothing is charged. If one of those numbers is in a country your organization can't send to yet, therecipients_ unsupported" failureReasonisall_instead.recipients_ not_ allowed - A campaign that failed when it was due can be sent again now.
Move it with PATCH / and a new scheduledAt, while it's still scheduled. Rescheduling needs auto top-up, as scheduling does. Rescheduling a transactional campaign also needs your organization approved for transactional messages; otherwise it's refused with 403 and feature_, and the campaign keeps its old time. Cancel it with POST /. You can cancel a scheduled or queued campaign, or a stalled one; messages already handed to the network can't be called back. Canceling or resuming a transactional campaign doesn't need approval.
Repeat it
POST / sends a campaign on a rule: weekly on the days you choose, monthly on a day of the month or its last day, or yearly on a date, each at a time in a time zone you choose. Its send is the body a campaign takes, without scheduledAt. About 45 minutes before each time, it creates a scheduled campaign, priced and charged when it sends.
Creating or resuming one needs auto top-up. Changing it doesn't. Recurring campaigns has the rule, what it creates, and how to change, pause or delete one.
Find your campaigns
- List them with
GET /, newest first.organizations/ {accountId}/ messages/ campaigns view=scheduledgives only those waiting for their time, soonest first;view=sentgives every other one, and withincludeCancelledset tofalseit leaves out the canceled ones.recurringCampaignIdnarrows the list to one recurring campaign's. It pages by cursor: see Paging through results. - Count them with
GET /:organizations/ {accountId}/ messages/ campaigns/ summary scheduledCount, and innotSent, how many scheduled campaigns, and large campaigns sent now, failed to go out in the last 7 days, with the latest one's ID. - Break an audience down by language before you write the text, with
POST /and theorganizations/ {accountId}/ messages/ audience recipientsandlistIdsyou'll send to. It counts who would get each language, and prices nothing. Addfields, up to 20 placeholder names, to see infieldshow many people have their own value for each, and insampleup to 8 people with their values, with yourdefaultsfilled in where they have none.
Each needs messages:read.
Send to the same people again
POST / sends the campaign again as a new campaign, priced and charged at today's prices. It sends each person the text they got last time. With "onlyFailed": true, it sends only to people whose message has status failed, rejected or undelivered, not to people who were skipped because they opted out, their number is one we can't send to, or it's in a country your organization can't send to yet. Anyone who has opted out since is skipped too, as on any marketing campaign.
It also leaves out people whose placeholders couldn't be filled in: their message's errorCode is missing_, unknown_, invalid_, value_, rendered_ or rendered_. Their stored text is usually the template itself, so it would go out with its {{placeholders}} as written, and the same values would fail the same way. Send them a new campaign with the missing values, or with defaults, instead. If no one is left to send to, the answer is 409 with nothing_, and nothing is charged.
Send a refused campaign again
A campaign that failed before it was accepted has status failed and a failureReason: a scheduled campaign that failed when it was due, or a large campaign sent now that failed once it was accepted. Once you've fixed the reason, for example by topping up, send it now with POST /. The API key needs messages:send, and the request takes an Idempotency-Key header.
A campaign that failed with all_ can't be sent again, because we can't send to those numbers. If you think we should be able to, email hello@codelia.studio. One that failed with unknown_ can't be sent again either, because a deleted list doesn't come back: send a new campaign to the lists you have now. Both are refused with 409 and not_. So is a campaign of up to 500 people you sent now that no one could be sent to: it was accepted when you sent it, and each person's message says why, so send to the same people again instead.
It's sent as a new campaign, with the same lists, numbers and text as when you scheduled or sent it. The lists are read again, so a smart list reaches whoever matches now, and it's priced and charged at today's prices. The answer is 202 with the new campaign. The failed campaign doesn't change.
To see what it would cost first, call GET /. It prices the campaign as it would go out now, sends nothing and charges nothing, and needs messages:read.
It's checked like any campaign you send now, so it can be refused for the same reasons. A refused attempt doesn't count, so you can fix the reason and try again. Neither does a new campaign that is itself large and fails before it's accepted: the failed campaign's sentAgainAt and sentAgainCampaignId go back to null, and you can send it again.
A failed campaign can be sent again once. After that, it's refused with 409 and not_, and sentAgainCampaignId is the campaign it was sent as: nothing more is sent or charged. While that campaign is still being created, sentAgainCampaignId is null. If that attempt was cut off and created nothing, you can send it again 15 minutes after it started. Any other campaign is refused the same way: to repeat a campaign that went out, use Send to the same people again.
When it's refused
A refused campaign sends nothing and charges nothing.
| Status | error | What happened | What to do |
|---|---|---|---|
| 400 | too_ | Your lists and recipients come to more than 100,000 people. | Split the audience across campaigns. |
| 400 | unknown_ | A list in listIds doesn't exist in your organization. | Check the list IDs. |
| 400 | no_ | The lists and recipients came to nobody. | Add people to the list, or send recipients. |
| 400 | all_ | We can't send to any of the numbers. Anyone else in the request opted out. Nothing was sent, scheduled or charged. | Check the numbers are right. If they are, email hello@codelia.studio. |
| 400 | all_ | Your organization can't send to these countries yet, and no one else is left to send to. Nothing was sent, scheduled or charged. | Email hello@codelia.studio to send to them. |
| 400 | reserved_ | A metadata key starts with audience.. | Rename the key. |
| 400 | invalid_ | scheduledAt is less than 5 minutes or more than 90 days ahead. | Choose a time in that window, or leave it out to send now. |
| 402 | insufficient_ | Your balance can't cover the estimated cost. | Top up, then send again with a new Idempotency-Key. |
| 409 | auto_ | You scheduled a campaign, and auto top-up isn't ready to pay for it. | Set up auto top-up in the portal, then schedule it again. |
| 409 | unsupported_ | A smart list's filter can't be read. | Edit the list to rebuild its filter. |
A large campaign sent now isn't refused here with too_, all_, all_, or insufficient_ for a balance above zero that's short: those arrive later as its failureReason.
A campaign is refused with sender_, unapproved_, default_ or organization_ for the same reasons as a message. A number the campaign can't send to (invalid_, sender_, no_, country_ or currency_) doesn't refuse it: that person's message fails with the code as its errorCode, and isn't charged. Every code is on Errors and limits.