Python helpers

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) -> dict

Adds 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

NameTypeDescription
campaign_idstrThe campaign's ID. It must be a continuous campaign of your organization that is a draft, running or paused.
recipientslist1 to 10,000 dicts, each with the recipient fields below
Recipient keyTypeDescription
phonestrRequired. E.164 format, e.g. "+15551234567"
namestrOptional. Spoken in the greeting through {name} or {firstName}. Max 500 characters
contextstrOptional. Free text the AI reads before the call. Max 2,000 characters
metadatadictOptional. JSON for your hooks and actions, never shown to the AI. Max 4 KB
dedupeKeystrOptional. 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 reused dedupeKeys. See De-duplication.
  • A number whose earlier call finished can be added again, unless its dedupeKey was used before.
  • Raises ValueError for a missing campaign_id or an empty list.
  • Raises requests.HTTPError when the campaign is one-shot, completed or canceled, isn't found, or a recipient is invalid. The response's JSON error says 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 result

The dedupeKey makes sure a cart found again on the next run isn't called twice.

On this page