PUT/ sms-campaign/ :id/
Add recipient SMS campaign
You can add recipients to an existing SMS campaign.
caution
Like Create SMS campaign, this endpoint needs a Twilio sender number (phone_number, with provider
"Twilio"), and User no longer offers Twilio. It works only in workspaces
that still have a Twilio number. Otherwise, create SMS campaigns in the
panel; you can still list, read and delete them through the API.
Attributes
Optional unless marked required
- id
- ID of the campaign, in the path. Only draft campaigns (
status1) can be changed; others return405. - recipients
- Contact IDs (
idfrom the User model) to send the campaign to. Contacts without a phone number are skipped, and contacts sharing a phone number count once. They are added to the campaign's current recipients. - phone_number
- Same object as in Create SMS campaign. It must be sent, but it doesn't change the campaign's sender number; a number the workspace doesn't have yet is still added and charged.
Other fields in the body are ignored: this endpoint only adds recipients.
Request
- cURL
- JavaScript
- PHP
- Python
curl -X PUT "https://<your_app_subdomain>.user.com/api/public/sms-campaign/:id/" \
-H "Authorization: Token <your_64_char_api_key>" \
-H "Accept: */*; version=2" \
-H "Content-Type: application/json" \
-d '{
"phone_number": {
"provider": "Twilio",
"phone_number": "+48500100200",
"name": "Main sender"
},
"recipients": [
5,
6,
7,
8
]
}'
const response = await fetch(
"https://<your_app_subdomain>.user.com/api/public/sms-campaign/:id/",
{
method: "PUT",
headers: {
Authorization: "Token <your_64_char_api_key>",
Accept: "*/*; version=2",
"Content-Type": "application/json",
},
body: JSON.stringify({
phone_number: {
provider: "Twilio",
phone_number: "+48500100200",
name: "Main sender",
},
recipients: [
5,
6,
7,
8,
],
}),
},
);
const data = await response.json();
console.log(data);
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://<your_app_subdomain>.user.com/api/public/sms-campaign/:id/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_HTTPHEADER => [
"Authorization: Token <your_64_char_api_key>",
"Accept: */*; version=2",
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"phone_number" => [
"provider" => "Twilio",
"phone_number" => "+48500100200",
"name" => "Main sender",
],
"recipients" => [
5,
6,
7,
8,
],
]),
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import requests
response = requests.put(
"https://<your_app_subdomain>.user.com/api/public/sms-campaign/:id/",
headers={
"Authorization": "Token <your_64_char_api_key>",
"Accept": "*/*; version=2",
},
json={
"phone_number": {
"provider": "Twilio",
"phone_number": "+48500100200",
"name": "Main sender",
},
"recipients": [
5,
6,
7,
8,
],
},
)
print(response.json())
Response examples
- 200 OK
- 404 Not Found
{"id": 8,"name": "Sample SMS campaign","description": "","app": 1,"phone_number": {"id": 3,"app": 1,"provider": "Phone number provider","country": "","phone_number": "123123123","name": "Custom name of your phone number","description": "","sms": false,"voice": false,"price": "0.00","last_used_at": null,"created_at": "2018-02-19T13:01:41.083625Z","updated_at": "2018-02-19T13:01:41.083655Z","record_incoming_calls": false},"type": 1,"eta": null,"status": 1,"recipients": [1,2,3,4,5,6,7,8],"recipients_ids": "[1,2,3,4,5,6,7,8]","recipients_count": 8,"started_at": null,"last_message_sent_at": null,"finished_at": null,"author": 1,"created_at": "2018-02-19T13:01:41.097096Z","updated_at": "2018-02-19T13:01:41.097126Z"}{
"detail": "SMS Campaign with ID 999999999 does not exist"
}
note
Errors that can come from any endpoint (401, 429, 500, 502, 504) are described in HTTP response codes.