Opt-outs
Someone who opts out doesn't get your marketing messages any more. They opt out with the link at the end of every marketing message, and you can add or remove an opt-out yourself. Opt-outs belong to your organization: opting out of your messages doesn't affect any other organization's, and theirs don't affect yours.
The unsubscribe line
Every marketing message ends with the unsubscribe line: a line break, STOPSMS and a link, like STOPSMS https:/. It's counted and priced with your text (see How messages are counted). A transactional message has none.
Each number gets one link for your organization, the same on every message you send it. Opening the link doesn't opt anyone out. The page shows your organization's name and the last two digits of the number, and the person chooses Unsubscribe to opt out.
What sending does with an opt-out
- Sending a message skips a number that opted out. It's in the answer with
status: "failed",errorCode: "opted_andout" priceMicros: 0, and itsoutcomeisopted_. When every number inout toopted out, the request is refused with400andall_.recipients_ opted_ out - A campaign skips them too and counts them in
skippedCount, notfailedCount. You aren't charged for them: it checks again just before handing each message to the network, and refunds anyone who opted out in between. If everyone on it opted out, nothing is handed over, so it finishesfailedand sendscampaign.failed. - A scheduled or recurring campaign checks opt-outs when it sends, not when it was scheduled.
- Pricing a message or campaign counts numbers that opted out as if they would get the message.
- A transactional message is sent even to a number that opted out.
Manage opt-outs yourself
List them, most recent first, with opt-outs:read. They page by limit (up to 1,000, and 200 if you leave it out) and offset: see Paging through results. To check one number, add phone: the list then holds that number's opt-out, or is empty when it hasn't opted out. Spaces, dashes and a leading 00 instead of + are fine, like +44 20 7946 0123 or 00442079460123. Include the country code.
curl "https://api.sms.codelia.studio/v1/organizations/$CODELIA_ACCOUNT_ID/opt-outs" \
-H "Authorization: Bearer $CODELIA_API_KEY"const response = await fetch(
`https://api.sms.codelia.studio/v1/organizations/${process.env.CODELIA_ACCOUNT_ID}/opt-outs`,
{
headers: {
Authorization: `Bearer ${process.env.CODELIA_API_KEY}`,
},
},
);
console.log(response.status);
console.log(JSON.stringify(await response.json(), null, 2));Each one has the phone, its source (link when the person used the link), a reason if one was given, and optedOutAt.
Add one with opt-outs:write when someone asks you to stop another way, by email, on the phone or at the counter:
curl -X POST "https://api.sms.codelia.studio/v1/organizations/$CODELIA_ACCOUNT_ID/opt-outs" \
-H "Authorization: Bearer $CODELIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"phone": "+442079460199",
"source": "manual",
"reason": "Asked by email to stop marketing messages."
}'const response = await fetch(
`https://api.sms.codelia.studio/v1/organizations/${process.env.CODELIA_ACCOUNT_ID}/opt-outs`,
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.CODELIA_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"phone": "+442079460199",
"source": "manual",
"reason": "Asked by email to stop marketing messages."
}),
},
);
console.log(response.status);
console.log(JSON.stringify(await response.json(), null, 2));source is manual (the default), api or imported, and reason is up to 500 characters. Adding one that already exists answers 201 again and replaces its source, reason and time.
- A contact's
optOutfield shows whether their number opted out, and only when the API key holdsopt-outs:read. - Deleting a contact keeps its number's opt-out.
- To be told when a number opts out or opts back in, subscribe a webhook endpoint to
contact.opted_andout contact.opted_. Each is sent only when something changes.in
Undo an opt-out
Someone who opted out with the link can opt back in from the same link. An opt-out you added can only be removed by you, with DELETE / and opt-outs:write.
Adding an opt-out with POST / for a number that opted out with the link turns it into yours, so the person can no longer undo it from the link. Only remove an opt-out when the person has asked to hear from you again.
Bring your existing opt-outs
Moving from another service, bring the numbers that opted out before your first campaign:
- Contacts you already have: send their contact IDs, up to 1,000 per request, to
POST /. A number that already opted out is left as it is, so an opt-out someone made with the link stays theirs to undo. The answer countsorganizations/ {accountId}/ opt-outs/ bulk optedOut,alreadyOptedOutandskipped(IDs that aren't your contacts). - Numbers one at a time:
POST /withorganizations/ {accountId}/ opt-outs "source": "imported". Skip numbers already in your list, so you don't take over someone's own opt-out. Each API key can make 60 requests a minute by default (see Rate limit).
What stays yours
In each country you send to, it's up to you to have each person's consent to your marketing messages, to choose the hours you send at, and to decide what your messages say.