Reten Docs

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

FieldTypeRequiredDescription
itemsarrayYesArray of activity objects (min 1, max 200)

Each item in items has the same fields as the Create Activity request body:

FieldTypeRequiredDescription
typestringYesTASK
reasonstringYesReason 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
channelstringYesSALESMAN, CALLCENTER
commerce_idUUIDConditionalTarget commerce ID. Send it or commerce_external_id: at least one is required. If you send both, commerce_id wins
commerce_external_idstringConditionalTarget commerce by external ID (max 255 characters). If no commerce has it, the API creates a placeholder commerce with that external ID
idempotency_keystringYesUnique key per tenant (prevents duplicates)
scheduled_atISO 8601YesWhen the activity should be executed
intent_categorystringNoONBOARDING, 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_reasonsarrayNoOrigin 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_idUUIDNoThe 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_idUUIDNoResult 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_timeISO 8601NoSuggested time for execution
user_statusstringNoUser status context. It must be an active code of the tenant's retention status catalog; otherwise the item fails with validation_error
scoreintegerNoPriority score
assignment_reasonstringNoReason for the assignment
activity_detailsobjectYes, for TASKRoute 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.

FieldTypeDescription
summaryobjectCounters: total (items received), created, skipped and failed
itemsarrayCreated activities: index, idempotencyKey, activityId
skippedarrayItems 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
errorsarrayFailed 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:

errorWhenExample message
validation_errorThe item passes body validation but breaks a creation ruleSe 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_errorreason is not an active reason of the tenant's catalog, either unknown or deactivatedActivity reason "<code>" is not configured for this tenant
validation_errorThe reason is context-dependent and the item has no intent_categoryActivity reason "<code>" has no default intent category; intent_category is required
not_foundcommerce_id, assigned_route_id or assigned_operator_id does not existCommerce not found, Route not found, Operator not found
not_foundorigin_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 commerceorigin_activity_result_id: activity result "<id>" not found
ACTIVITY_FORM_NOT_FOUNDform_id is not a form of the active project or of the tenant, either unknown or of another projectNo existe el formulario <id>.
ACTIVITY_FORM_CATEGORY_MISMATCHThe form of form_id is of another category than the itemEl formulario <id> es de otra categoría que la gestión (SALES).
ACTIVITY_FORM_NOT_RESOLVEDThe item has no form_id, and neither the project nor the tenant has a default form of its categoryNo hay un formulario por defecto de la categoría SALES: indica uno o marca uno por defecto.
creation_errorAny other failure — for example, the idempotency_key is already used by an activity of another project of the tenantLa 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

StatusDescription
400Invalid 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
401Missing or invalid authentication token
403Missing activity:create permission