All endpoints should pass in the
userId in the request body. You can find your userId in the sa.dialgen.ai dashboard.-
Endpoint:
POST /api/v1/batch -
Method:
POST -
Request Body:
Request Parameters
-
agentId(string, required): The agent ID to use for the entire batch. -
userId(string, required): The user ID owning the agent. -
contacts(array, required): An array of contact objects (min: 1, max: 100,000 per batch). Contact Object Fields:id(string, optional): If the contact already exists in your database, provide the existing contact ID. The system will:- Reuse the existing contact and preserve its call history
- Update the contact to be part of this new batch
- Reset attempt counts for the new campaign
- Note: If both
idandphoneNumbermatch an existing contact, the contact will be updated, not duplicated.
phoneNumber(string, required): E.164 formatted phone number (minimum 10 characters).name(string, optional): Contact’s name (defaults to “Unknown”).email(string, optional): Contact’s email address (must be valid email format if provided).company(string, optional): Contact’s company name.metadata(object, optional): Custom key-value pairs for additional contact information (e.g., lead score, account ID, custom fields).
-
options(object, optional): Batch processing configuration.priority(number, optional): Priority level from 1-10 (default: 5). Higher priority batches are processed first.scheduledStartTime(string, optional): ISO 8601 datetime string for scheduling the batch to start in the future. Must be a future time.timezone(string, optional): Timezone for scheduling (default: “UTC”).maxCallsPerSecond(number, optional): Rate limiting for calls (min: 1, max: 30, default: 10).retryStrategy(object, optional): Configuration for retry logic.maxAttempts(number, optional): Maximum retry attempts per contact (min: 1, max: 5, default: 3).noAnswerDelay(number, optional): Delay in milliseconds before retrying a no-answer call (default: 3600000 = 1 hour).busyDelay(number, optional): Delay in milliseconds before retrying a busy call (default: 300000 = 5 minutes).
webhooks(object, optional): Webhook URLs for event notifications.onBatchComplete(string, optional): Called when the entire batch finishes processing.onCallComplete(string, optional): Called after each individual call completes.onBatchFailed(string, optional): Called if the batch fails.
tags(array of strings, optional): Tags for filtering and grouping batches.
Contact Deduplication & History Preservation
The batch API intelligently handles duplicate contacts to preserve call history:- By Contact ID: If you provide an
idthat exists in the database for this agent, the existing contact record is reused and moved to the new batch. - By Phone Number: If a
phoneNumbermatches an existing contact (normalized), the existing contact is reused. - New Contacts: Only truly new contacts (no matching ID or phone number) are created.
- Batch Assignment: Existing contacts are automatically reassigned to the new batch with reset attempt counts, ensuring they’re included in the campaign without losing historical data.
-
Scenario 1: You provide
id: "contact_123"and it exists → Contact is moved to new batch, history preserved. -
Scenario 2: You provide
phoneNumber: "+15551234567"that exists → Contact is matched by phone, moved to new batch. -
Scenario 3: You provide both
idandphoneNumberthat don’t exist → New contact is created. -
Scenario 4: You provide
id: "contact_123"but a differentphoneNumber→ Contact ID takes precedence, phone number is updated. -
Success Response (202 Accepted):
The server acknowledges the request. Use the returned
batchIdfor monitoring. -
Error Responses:
400 Bad Request - Validation Failed:
400 Bad Request - Scheduled Time Invalid:402 Payment Required - Insufficient Credits:404 Not Found - Agent Not Found:500 Internal Server Error:
Batch Processing Workflow
When you submit a batch, the following process occurs:- Validation (Immediate): Request is validated for required fields, contact format, and agent existence.
- Pre-flight Checks (Immediate):
- Agent must exist and be active
- User must have sufficient call minutes (estimated at 2 minutes per contact)
- Scheduled start time must be in the future (if provided)
- Ingestion (Background): Contacts are processed in chunks of 500:
- Existing contacts (by ID or phone number) are identified and moved to the new batch
- New contacts are created in bulk
- Duplicate contacts within the batch are automatically handled
- Call history is preserved for existing contacts
- Scheduling (Background): Once ingestion completes:
- If
scheduledStartTimeis provided, batch status becomesscheduled - Otherwise, batch processing begins immediately
- If
- Processing (Background): Calls are initiated according to:
- Priority level (higher priority batches first)
- Rate limiting (
maxCallsPerSecond) - Retry strategy for failed calls
ingesting→ Contacts are being added to the databasescheduled→ Ingestion complete, waiting for scheduled start timepending→ Ready to start processing callsprocessing→ Actively making callscompleted→ All calls finished