Opt a contact out
curl --request POST \
--url https://api.sendbaze.com/v1/contacts/{id}/opt-out \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"channel": "sms"
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({channel: 'sms'})
};
fetch('https://api.sendbaze.com/v1/contacts/{id}/opt-out', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.sendbaze.com/v1/contacts/{id}/opt-out"
payload = { "channel": "sms" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)require 'uri'
require 'net/http'
url = URI("https://api.sendbaze.com/v1/contacts/{id}/opt-out")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"channel\": \"sms\"\n}"
response = http.request(request)
puts response.read_body<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.sendbaze.com/v1/contacts/{id}/opt-out",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'channel' => 'sms'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.sendbaze.com/v1/contacts/{id}/opt-out"
payload := strings.NewReader("{\n \"channel\": \"sms\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"id": "ct_01j9x7k2r4m8q3v5n6b7c8d9e0",
"email": "<string>",
"phone": "<string>",
"attributes": {
"first_name": "Thandi",
"city": "Pretoria"
},
"marketing": {
"email": {
"consented": true,
"optedOutAt": "2023-11-07T05:31:56Z"
},
"sms": {
"consented": true,
"optedOutAt": "2023-11-07T05:31:56Z"
}
},
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z",
"consents": [
{
"id": "cns_01j9x7k2r4m8q3v5n6b7c8d9e0",
"contactId": "<string>",
"channel": "email",
"value": "<string>",
"purpose": "marketing",
"source": "form",
"evidence": {},
"capturedAt": "2023-11-07T05:31:56Z",
"recordedAt": "2023-11-07T05:31:56Z",
"revokedAt": "2023-11-07T05:31:56Z",
"revokedReason": "<string>"
}
]
}{
"error": {
"code": "not_found",
"message": "No email with id em_x.",
"docs": "https://docs.sendbaze.com/errors#not_found"
}
}{
"error": {
"code": "validation_error",
"message": "<string>",
"docs": "<string>",
"fields": {},
"limit": 123,
"upgradeUrl": "<string>",
"topUpUrl": "<string>",
"settingsUrl": "<string>",
"domainsUrl": "<string>"
}
}Contacts and consent
Opt a contact out
Opts the contact out of marketing on a channel. Its consents on that channel are revoked and the address or number is suppressed for marketing; transactional messages still send. Idempotent. Requires contacts:write.
POST
/
v1
/
contacts
/
{id}
/
opt-out
Opt a contact out
curl --request POST \
--url https://api.sendbaze.com/v1/contacts/{id}/opt-out \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"channel": "sms"
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({channel: 'sms'})
};
fetch('https://api.sendbaze.com/v1/contacts/{id}/opt-out', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.sendbaze.com/v1/contacts/{id}/opt-out"
payload = { "channel": "sms" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)require 'uri'
require 'net/http'
url = URI("https://api.sendbaze.com/v1/contacts/{id}/opt-out")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"channel\": \"sms\"\n}"
response = http.request(request)
puts response.read_body<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.sendbaze.com/v1/contacts/{id}/opt-out",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'channel' => 'sms'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.sendbaze.com/v1/contacts/{id}/opt-out"
payload := strings.NewReader("{\n \"channel\": \"sms\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"id": "ct_01j9x7k2r4m8q3v5n6b7c8d9e0",
"email": "<string>",
"phone": "<string>",
"attributes": {
"first_name": "Thandi",
"city": "Pretoria"
},
"marketing": {
"email": {
"consented": true,
"optedOutAt": "2023-11-07T05:31:56Z"
},
"sms": {
"consented": true,
"optedOutAt": "2023-11-07T05:31:56Z"
}
},
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z",
"consents": [
{
"id": "cns_01j9x7k2r4m8q3v5n6b7c8d9e0",
"contactId": "<string>",
"channel": "email",
"value": "<string>",
"purpose": "marketing",
"source": "form",
"evidence": {},
"capturedAt": "2023-11-07T05:31:56Z",
"recordedAt": "2023-11-07T05:31:56Z",
"revokedAt": "2023-11-07T05:31:56Z",
"revokedReason": "<string>"
}
]
}{
"error": {
"code": "not_found",
"message": "No email with id em_x.",
"docs": "https://docs.sendbaze.com/errors#not_found"
}
}{
"error": {
"code": "validation_error",
"message": "<string>",
"docs": "<string>",
"fields": {},
"limit": 123,
"upgradeUrl": "<string>",
"topUpUrl": "<string>",
"settingsUrl": "<string>",
"domainsUrl": "<string>"
}
}Authorizations
Response
The contact after the opt-out