add_campaign_recipients
Feed a continuous phone campaign from your own systems by adding people to its calling queue.
add_campaign_recipients(campaign_id: str, recipients: list) -> dictAdds people to the calling queue of a continuous phone campaign, so your own systems decide who the AI agent calls. For example, a recurring job can find policies due for renewal and add those customers every morning. It also works in event handlers and custom actions. It does the same as the REST endpoint and needs no API key.
Parameters
| Name | Type | Description |
|---|---|---|
campaign_id | str | The campaign's ID. It must be a continuous campaign of your organization that is a draft, running or paused. |
recipients | list | 1 to 10,000 dicts, each with the recipient fields below |
| Recipient key | Type | Description |
|---|---|---|
phone | str | Required. E.164 format, e.g. "+15551234567" |
name | str | Optional. Spoken in the greeting through {name} or {firstName}. Max 500 characters |
context | str | Optional. Free text the AI reads before the call. Max 2,000 characters |
metadata | dict | Optional. JSON for your hooks and actions, never shown to the AI. Max 4 KB |
dedupeKey | str | Optional. A key already used in this campaign, even by a finished call, is skipped forever |
Returns
dict: {"added": int, "skippedDuplicates": int}
Behavior
- Duplicates are skipped and counted in
skippedDuplicates: repeats within the call, numbers already waiting or being called in the campaign, and reuseddedupeKeys. See De-duplication. - A number whose earlier call finished can be added again, unless its
dedupeKeywas used before. - Raises
ValueErrorfor a missingcampaign_idor an empty list. - Raises
requests.HTTPErrorwhen the campaign is one-shot, completed or canceled, isn't found, or a recipient is invalid. The response's JSONerrorsays why.
Examples
Call abandoned carts from a recurring job
CAMPAIGN_ID = "00000000-0000-0000-0000-000000000000"
def run_job(context):
carts = find_abandoned_carts(minutes=60) # your own lookup
if not carts:
return {"added": 0}
result = add_campaign_recipients(
CAMPAIGN_ID,
[
{
"phone": cart["phone"],
"name": cart["first_name"],
"context": f"Left {cart['items']} in the cart.",
"metadata": {"cartId": cart["id"]},
"dedupeKey": f"cart-{cart['id']}",
}
for cart in carts
],
)
return resultThe dedupeKey makes sure a cart found again on the next run isn't called twice.