Enroll Contacts in a Campaign
POST /v1/campaigns/{campaign_id}/contacts
| Property | Value |
|---|---|
| Operation | enroll_campaign_contacts |
| Group | Campaigns |
| Scope | campaigns:write |
| Route class | control |
| Idempotency | Idempotency-Key required: a retry with the same key replays the first answer |
| Audit | Audited campaigns.enrollment.create (mutation) |
| Released in | 1.65.0 |
| Phase 0 host | Served (the hosted api pins 1.65.0) |
Enrolls up to 100 Contacts by id or by inline identities, upserted as Contacts, or a completed Contact import as a campaign.enrollment_import job, from draft until enrollment_closes_at (1.65.0; section 3.1). Each enrollment is unique per Campaign and Contact, so a Contact already enrolled answers its enrollment with created false; one that fails a check is recorded ineligible with its code. A Campaign whose enrollment closed or that ended is campaign_conflict; variables in an Organization that keeps no content are zero_retention_variables_not_allowed. The Idempotency-Key makes a repeated request answer the same batch.
Request
Set VOCAL_API to the base URL of your API and VOCAL_API_KEY to an API key with the campaigns:write scope (Authentication and keys). Replace each placeholder, such as agt_... or <name>, with your own value.
curl -X POST "$VOCAL_API/v1/campaigns/cmp_.../contacts" \
-H "Authorization: Bearer $VOCAL_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{}'const response = await fetch(`${process.env.VOCAL_API}/v1/campaigns/cmp_.../contacts`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.VOCAL_API_KEY}`,
'Idempotency-Key': crypto.randomUUID(),
'Content-Type': 'application/json',
},
body: JSON.stringify({}),
});
console.log(response.status, await response.text());import os
import uuid
import requests
response = requests.post(
f"{os.environ['VOCAL_API']}/v1/campaigns/cmp_.../contacts",
headers={
"Authorization": f"Bearer {os.environ['VOCAL_API_KEY']}",
"Idempotency-Key": str(uuid.uuid4()),
},
json={},
)
print(response.status_code, response.text)Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
campaign_id | path | CampaignId | yes | The id of a Campaign: cmp_ and the row's UUIDv7 in 26 Crockford base32 characters. Opaque and safe to log. |
idempotency-key | header | string | yes | A client-chosen key, kept 24 hours per Organization, environment and route. A replay returns the stored response. |
Request body
Content type application/json, required: CampaignEnrollRequest.
| Field | Type | Required | Description |
|---|---|---|---|
contacts | array of CampaignEnrollItemInput | no | |
import_id | ContactImportId | no | A completed Contact import whose Contacts are enrolled by a job. |
Responses
| Status | Content type | Shape | Error codes |
|---|---|---|---|
200 | application/json | CampaignEnrollmentBatch | |
400 | application/json | ErrorEnvelope | invalid_request |
401 | application/json | ErrorEnvelope | unauthenticated |
403 | application/json | ErrorEnvelope | forbidden, org_suspended |
404 | application/json | ErrorEnvelope | not_found |
409 | application/json | ErrorEnvelope | campaign_conflict, idempotency_in_progress, idempotency_key_reused |
422 | application/json | ErrorEnvelope | validation_failed |
429 | application/json | ErrorEnvelope | rate_limited |
500 | application/json | ErrorEnvelope | internal_error |
Fields of the 200 answer
The shape is CampaignEnrollmentBatch.
| Field | Type | Required | Description |
|---|---|---|---|
campaign_id | CampaignId | yes | |
items | array of CampaignEnrollItemResult | yes | One per item, in order; empty for an import. |
job | Job or null | yes | The import job; null for inline items. |
object | "campaign_enrollment_batch" | yes |