Bulk Create Activities
Create multiple activities in a single request.
POST /api/activities/bulk
Create up to 200 activities in a single request. Each item follows the same schema as the single Create Activity endpoint.
Auth: Required — activity:create permission
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
items | array | Yes | Array of activity objects (min 1, max 200) |
Each item in items has the same fields as the Create Activity request body:
| Field | Type | Required | Description |
|---|---|---|---|
type | string | Yes | TASK |
reason | string | Yes | Reason code: lowercase letters, digits and _ only (^[a-z0-9_]+$), max 100 characters. It must be an active reason of the tenant's catalog; otherwise the item fails with validation_error |
channel | string | Yes | SALESMAN, CALLCENTER |
commerce_id | UUID | Conditional | Target commerce ID. Send it or commerce_external_id: at least one is required. If you send both, commerce_id wins |
commerce_external_id | string | Conditional | Target commerce by external ID (max 255 characters). If no commerce has it, the API creates a placeholder commerce with that external ID |
idempotency_key | string | Yes | Unique key per tenant (prevents duplicates) |
scheduled_at | ISO 8601 | Yes | When the activity should be executed |
intent_category | string | No | ONBOARDING, MARKETING, COLLECTION, RETENTION, NOTIFICATION, SURVEY, VALIDATION, SALES, CREDIT, OPERATIONAL or DIGITAL_ADOPTION. If sent, it wins over the reason's category; if the key is omitted, the activity takes the reason's current category. null responds 400 for the whole batch |
origin_reasons | array | No | Origin reasons: up to 10 { code, description } items. code takes lowercase letters, digits and _ only (^[a-z0-9_]+$), max 100 characters; description cannot be empty or only spaces, max 500 characters. The list is stored and returned in the order sent, with no meaning given to the order or to any item (see Create Activity). Omitted or [], the activity has no origin reasons. null, an invalid item or a key besides code and description responds 400 for the whole batch |
origin_activity_result_id | UUID | No | The activity result that originated the activity. It must be an activity result of the active project, or the item fails with not_found; it can be a STANDALONE one (see Create Activity). Omitted, the activity has no origin activity result. null or a value that is not a UUID responds 400 for the whole batch |
form_id | UUID | No | Result form the task is answered with (see Activity Forms). It must be a form of the active project or of the tenant, and of the category of the activity; it does not need to be a default form. If the key is omitted, the task takes the default form of its category: the one of its project and, if the project has none, the one of the tenant. null responds 400 for the whole batch; a form that does not fit makes the item fail with the code of the error (see below) |
suggested_execution_time | ISO 8601 | No | Suggested time for execution |
user_status | string | No | User status context. It must be an active code of the tenant's retention status catalog; otherwise the item fails with validation_error |
score | integer | No | Priority score |
assignment_reason | string | No | Reason for the assignment |
activity_details | object | Yes, for TASK | Route and operator assignment (see Create Activity). A TASK item without it fails with validation_error |
Example
curl -X POST https://api.reten.ai/api/activities/bulk \
-H "Authorization: Bearer <token>" \
-H "x-tenant-id: <tenant-id>" \
-H "x-project-id: <project-id>" \
-H "Content-Type: application/json" \
-d '{
"items": [
{
"type": "TASK",
"reason": "monthly_visit",
"channel": "SALESMAN",
"commerce_id": "880e8400-e29b-41d4-a716-446655440000",
"idempotency_key": "task-2025-01-15-001",
"scheduled_at": "2025-01-16T09:00:00.000Z",
"origin_reasons": [
{ "code": "repurchase", "description": "Recompra: compra cada 15 días" }
],
"origin_activity_result_id": "ab0e8400-e29b-41d4-a716-446655440000",
"activity_details": {
"assigned_route_id": "dd0e8400-e29b-41d4-a716-446655440000",
"assigned_operator_id": "cc0e8400-e29b-41d4-a716-446655440000"
}
},
{
"type": "TASK",
"reason": "monthly_visit",
"channel": "CALLCENTER",
"commerce_external_id": "SHOP-0042",
"idempotency_key": "task-2025-01-15-002",
"scheduled_at": "2025-01-16T09:00:00.000Z",
"activity_details": {
"assigned_route_external_id": "ROUTE-07",
"assigned_operator_external_id": "AGENT-15"
}
}
]
}'const response = await fetch("https://api.reten.ai/api/activities/bulk", {
method: "POST",
headers: {
"Authorization": "Bearer <token>",
"x-tenant-id": "<tenant-id>",
"x-project-id": "<project-id>",
"Content-Type": "application/json",
},
body: JSON.stringify({
items: [
{
type: "TASK",
reason: "monthly_visit",
channel: "SALESMAN",
commerce_id: "880e8400-e29b-41d4-a716-446655440000",
idempotency_key: "task-2025-01-15-001",
scheduled_at: "2025-01-16T09:00:00.000Z",
origin_reasons: [
{ code: "repurchase", description: "Recompra: compra cada 15 días" },
],
origin_activity_result_id: "ab0e8400-e29b-41d4-a716-446655440000",
activity_details: {
assigned_route_id: "dd0e8400-e29b-41d4-a716-446655440000",
assigned_operator_id: "cc0e8400-e29b-41d4-a716-446655440000",
},
},
{
type: "TASK",
reason: "monthly_visit",
channel: "CALLCENTER",
commerce_external_id: "SHOP-0042",
idempotency_key: "task-2025-01-15-002",
scheduled_at: "2025-01-16T09:00:00.000Z",
activity_details: {
assigned_route_external_id: "ROUTE-07",
assigned_operator_external_id: "AGENT-15",
},
},
],
}),
});
const result = await response.json();import requests
response = requests.post(
"https://api.reten.ai/api/activities/bulk",
headers={
"Authorization": "Bearer <token>",
"x-tenant-id": "<tenant-id>",
"x-project-id": "<project-id>",
},
json={
"items": [
{
"type": "TASK",
"reason": "monthly_visit",
"channel": "SALESMAN",
"commerce_id": "880e8400-e29b-41d4-a716-446655440000",
"idempotency_key": "task-2025-01-15-001",
"scheduled_at": "2025-01-16T09:00:00.000Z",
"origin_reasons": [
{"code": "repurchase", "description": "Recompra: compra cada 15 días"},
],
"origin_activity_result_id": "ab0e8400-e29b-41d4-a716-446655440000",
"activity_details": {
"assigned_route_id": "dd0e8400-e29b-41d4-a716-446655440000",
"assigned_operator_id": "cc0e8400-e29b-41d4-a716-446655440000",
},
},
{
"type": "TASK",
"reason": "monthly_visit",
"channel": "CALLCENTER",
"commerce_external_id": "SHOP-0042",
"idempotency_key": "task-2025-01-15-002",
"scheduled_at": "2025-01-16T09:00:00.000Z",
"activity_details": {
"assigned_route_external_id": "ROUTE-07",
"assigned_operator_external_id": "AGENT-15",
},
},
],
},
)
result = response.json()Response 201 Created
Once the body passes validation, the API always responds 201 Created, even if every item fails. Items are processed one at a time, in order, and a failed item does not affect the others. The body reports the outcome of each item; index is the item's 0-based position in items.
| Field | Type | Description |
|---|---|---|
summary | object | Counters: total (items received), created, skipped and failed |
items | array | Created activities: index, idempotencyKey, activityId |
skipped | array | Items whose idempotency_key already belongs to an activity of the active project: index, idempotencyKey, existingActivityId. Nothing is created or changed, whatever the status of that activity |
errors | array | Failed items: index, idempotencyKey, error, message |
error is one of the generic codes below or, when the item fails with a business error, the stable code of that error; message is the API's message for that item:
error | When | Example message |
|---|---|---|
validation_error | The item passes body validation but breaks a creation rule | Se requiere al menos uno de los campos commerce_id o commerce_external_id., TASK activities require activityDetails, assigned_route_id is required for TASK activities |
validation_error | reason is not an active reason of the tenant's catalog, either unknown or deactivated | Activity reason "<code>" is not configured for this tenant |
validation_error | The reason is context-dependent and the item has no intent_category | Activity reason "<code>" has no default intent category; intent_category is required |
not_found | commerce_id, assigned_route_id or assigned_operator_id does not exist | Commerce not found, Route not found, Operator not found |
not_found | origin_activity_result_id is not an activity result of the active project, either unknown or of another project. It is checked before resolving the commerce, so the item does not create a placeholder commerce | origin_activity_result_id: activity result "<id>" not found |
ACTIVITY_FORM_NOT_FOUND | form_id is not a form of the active project or of the tenant, either unknown or of another project | No existe el formulario <id>. |
ACTIVITY_FORM_CATEGORY_MISMATCH | The form of form_id is of another category than the item | El formulario <id> es de otra categoría que la gestión (SALES). |
ACTIVITY_FORM_NOT_RESOLVED | The item has no form_id, and neither the project nor the tenant has a default form of its category | No hay un formulario por defecto de la categoría SALES: indica uno o marca uno por defecto. |
creation_error | Any other failure — for example, the idempotency_key is already used by an activity of another project of the tenant | La clave de idempotencia ya está en uso. |
An idempotency_key already used in another project is reported as a creation_error item, never as an HTTP 409.
Example for a batch of three items: the first is created, the second has an idempotency_key that already exists in the project, and the third references a commerce that does not exist.
{
"summary": {
"total": 3,
"created": 1,
"skipped": 1,
"failed": 1
},
"items": [
{
"index": 0,
"idempotencyKey": "task-2025-01-15-001",
"activityId": "ee0e8400-e29b-41d4-a716-446655440000"
}
],
"skipped": [
{
"index": 1,
"idempotencyKey": "task-2025-01-14-007",
"existingActivityId": "ff0e8400-e29b-41d4-a716-446655440000"
}
],
"errors": [
{
"index": 2,
"idempotencyKey": "task-2025-01-15-003",
"error": "not_found",
"message": "Commerce not found"
}
]
}Error Responses
| Status | Description |
|---|---|
400 | Invalid body: items is empty or has more than 200 elements, or an item has an invalid or missing field, or a field the endpoint does not accept. An invalid or null intent_category, origin_reasons, origin_activity_result_id or form_id is reported naming the item, for example items.1.intent_category or items.1.origin_reasons. Nothing is created |
401 | Missing or invalid authentication token |
403 | Missing activity:create permission |