curl --request POST \
--url https://api.politicalcomms.com/v1/projects/{id}/recipients \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"phone_number": "+12025550141",
"fields": {
"first_name": "Ada",
"amount": 25
},
"occurrence_id": "evt_123"
}
'import requests
url = "https://api.politicalcomms.com/v1/projects/{id}/recipients"
payload = {
"phone_number": "+12025550141",
"fields": {
"first_name": "Ada",
"amount": 25
},
"occurrence_id": "evt_123"
}
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
phone_number: '+12025550141',
fields: {first_name: 'Ada', amount: 25},
occurrence_id: 'evt_123'
})
};
fetch('https://api.politicalcomms.com/v1/projects/{id}/recipients', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.politicalcomms.com/v1/projects/{id}/recipients",
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([
'phone_number' => '+12025550141',
'fields' => [
'first_name' => 'Ada',
'amount' => 25
],
'occurrence_id' => 'evt_123'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <api-key>"
],
]);
$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.politicalcomms.com/v1/projects/{id}/recipients"
payload := strings.NewReader("{\n \"phone_number\": \"+12025550141\",\n \"fields\": {\n \"first_name\": \"Ada\",\n \"amount\": 25\n },\n \"occurrence_id\": \"evt_123\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<api-key>")
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))
}HttpResponse<String> response = Unirest.post("https://api.politicalcomms.com/v1/projects/{id}/recipients")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"phone_number\": \"+12025550141\",\n \"fields\": {\n \"first_name\": \"Ada\",\n \"amount\": 25\n },\n \"occurrence_id\": \"evt_123\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.politicalcomms.com/v1/projects/{id}/recipients")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"phone_number\": \"+12025550141\",\n \"fields\": {\n \"first_name\": \"Ada\",\n \"amount\": 25\n },\n \"occurrence_id\": \"evt_123\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"status": "already_entered",
"reason": "duplicate"
}
}Add Recipient
Add one recipient to a triggered project, the way an api trigger works: call this when something happens in your CRM or form. The message sends after the trigger’s delay_minutes; a text that comes due between 10 PM and 8 AM in the recipient’s time zone (by area code) is held until 8 AM. Opted-out numbers are never sent to and return 409 CONTACT_OPTED_OUT.
The project must be started and not paused. A paused or never started project refuses new recipients with 409 rather than queueing them. A person enters once: a second entry for the same person returns 200 already_entered. Send an occurrence_id so a retry of the same event is a no-op (200 already_entered). A malformed body (a missing or badly formatted phone_number, an unknown key) is a 400. A well-formed US-style number that cannot be texted, because its area code is outside the United States, is a 422 with details.reason invalid_phone.
curl --request POST \
--url https://api.politicalcomms.com/v1/projects/{id}/recipients \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"phone_number": "+12025550141",
"fields": {
"first_name": "Ada",
"amount": 25
},
"occurrence_id": "evt_123"
}
'import requests
url = "https://api.politicalcomms.com/v1/projects/{id}/recipients"
payload = {
"phone_number": "+12025550141",
"fields": {
"first_name": "Ada",
"amount": 25
},
"occurrence_id": "evt_123"
}
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
phone_number: '+12025550141',
fields: {first_name: 'Ada', amount: 25},
occurrence_id: 'evt_123'
})
};
fetch('https://api.politicalcomms.com/v1/projects/{id}/recipients', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.politicalcomms.com/v1/projects/{id}/recipients",
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([
'phone_number' => '+12025550141',
'fields' => [
'first_name' => 'Ada',
'amount' => 25
],
'occurrence_id' => 'evt_123'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <api-key>"
],
]);
$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.politicalcomms.com/v1/projects/{id}/recipients"
payload := strings.NewReader("{\n \"phone_number\": \"+12025550141\",\n \"fields\": {\n \"first_name\": \"Ada\",\n \"amount\": 25\n },\n \"occurrence_id\": \"evt_123\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<api-key>")
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))
}HttpResponse<String> response = Unirest.post("https://api.politicalcomms.com/v1/projects/{id}/recipients")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"phone_number\": \"+12025550141\",\n \"fields\": {\n \"first_name\": \"Ada\",\n \"amount\": 25\n },\n \"occurrence_id\": \"evt_123\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.politicalcomms.com/v1/projects/{id}/recipients")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"phone_number\": \"+12025550141\",\n \"fields\": {\n \"first_name\": \"Ada\",\n \"amount\": 25\n },\n \"occurrence_id\": \"evt_123\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"status": "already_entered",
"reason": "duplicate"
}
}Authorizations
Authenticate every request by passing your API key in the X-API-Key header. Keys are scoped to your organization hierarchy. A key carries up to three permissions: public:read for GET requests, public:write for POST, PATCH, and PUT requests, and public:delete for DELETE requests. public:delete is only available together with public:write.
Headers
Optional idempotency key: a unique string of 16-200 printable ASCII characters (a UUID is recommended). Retrying the write with the same key within 24 hours returns the stored response of the first call with an X-Idempotent-Replayed: true response header instead of executing it again. Reusing a key with a different request body returns 422 (IDEMPOTENCY_MISMATCH); a duplicate sent while the first call is still running returns 409 with a Retry-After header. Keys are scoped per endpoint and organization.
16 - 200Body
Optional values for this recipient, up to 50 keys with scalar values. Each is stored as a string of up to 1024 characters, can be used as a merge tag in the message (for example {first_name}), and appears in reports, exports and the contact.custom_fields of outbound webhooks.
Show child attributes
Show child attributes
