Reten Docs

Create Activity

Create a new activity assigned to a commerce.

POST /api/activities

Create a new TASK activity with commerce assignment.

Auth: Required — activity:create permission

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
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
origin_reasonsarrayNoOrigin reasons: the commercial context the activity was created for, as { code, description } items (see below). Omitted or [], the activity has no origin reasons. null responds 400
origin_activity_result_idUUIDNoThe activity result that originated the activity (see below). It must be an activity result of the active project. Omitted, the activity has no origin activity result. null responds 400
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
suggested_execution_timeISO 8601NoSuggested time for execution
user_statusstringNoUser status context. It must be an active code of the tenant's retention status catalog
scoreintegerNoPriority score
assignment_reasonstringNoReason for the assignment
activity_detailsobjectYes, for TASKType-specific details — shape depends on type (see below)

If the reason is context-dependent (intentCategory: null), it has no default category, so an activity without intent_category is rejected with 400.

activity_details

For type: "TASK", the activity_details object carries route/operator assignment and is required. Both a route and an operator are required, each by ID or by external ID; if you send both forms, the ID wins. An external ID that no route or operator has makes the API create a placeholder with it.

FieldTypeRequiredDescription
assigned_route_idUUIDConditionalAssigned route. Send it or assigned_route_external_id
assigned_route_external_idstringConditionalAssigned route by external ID (max 255 characters)
assigned_operator_idUUIDConditionalAssigned operator. Send it or assigned_operator_external_id
assigned_operator_external_idstringConditionalAssigned operator by external ID (max 255 characters)

origin_reasons

A list of up to 10 items that you define. The code is yours: it is not validated against any catalog, and two items can share it. The API stores the list and returns it in the order you sent it, without giving that order or any item a meaning: none of them is the main one. The list does not change after the activity is created.

FieldTypeRequiredDescription
codestringYesLowercase letters, digits and _ only (^[a-z0-9_]+$), max 100 characters
descriptionstringYesFree text, max 500 characters. Empty or only spaces responds 400. It is stored as sent

An item with any key besides code and description responds 400.

origin_activity_result_id

The ID of the activity result that originated the activity, for example the visit where the customer asked to reschedule. It must be an activity result of the active project: one that does not exist and one of another project both respond 404, and nothing is created. It can be a STANDALONE result, registered without an activity, and it does not have to be of the same commerce as the activity.

The activity keeps the reference, not a copy: the detail endpoints summarize the result as it is when you read them.

Example

curl -X POST https://api.reten.ai/api/activities \
  -H "Authorization: Bearer <token>" \
  -H "x-tenant-id: <tenant-id>" \
  -H "x-project-id: <project-id>" \
  -H "Content-Type: application/json" \
  -d '{
    "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",
    "intent_category": "SALES",
    "origin_reasons": [
      { "code": "seller_scheduled", "description": "El cliente pidió reagendar la visita" },
      { "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"
    }
  }'
const response = await fetch("https://api.reten.ai/api/activities", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <token>",
    "x-tenant-id": "<tenant-id>",
    "x-project-id": "<project-id>",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    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",
    intent_category: "SALES",
    origin_reasons: [
      { code: "seller_scheduled", description: "El cliente pidió reagendar la visita" },
      { 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",
    },
  }),
});
const activity = await response.json();
import requests

response = requests.post(
    "https://api.reten.ai/api/activities",
    headers={
        "Authorization": "Bearer <token>",
        "x-tenant-id": "<tenant-id>",
        "x-project-id": "<project-id>",
    },
    json={
        "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",
        "intent_category": "SALES",
        "origin_reasons": [
            {"code": "seller_scheduled", "description": "El cliente pidió reagendar la visita"},
            {"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",
        },
    },
)
activity = response.json()

Response 201 Created

A TASK activity is created in READY and can be dispatched right away: the identity of the assigned commerce is all dispatch needs. See Activity States for the full catalog.

If an activity of the active project already has that idempotency_key, the API creates nothing and responds 200 OK with the existing activity.

{
  "id": "ee0e8400-e29b-41d4-a716-446655440000",
  "projectId": "3f6c2b1a-8d4e-4f7a-9b2c-5e1d0a7f6c34",
  "type": "TASK",
  "reasonConfigId": "990e8400-e29b-41d4-a716-446655440000",
  "userStatusConfigId": null,
  "score": null,
  "templateId": null,
  "channel": "SALESMAN",
  "intentCategory": "SALES",
  "originReasons": [
    {
      "code": "seller_scheduled",
      "description": "El cliente pidió reagendar la visita"
    },
    {
      "code": "repurchase",
      "description": "Recompra: compra cada 15 días"
    }
  ],
  "originActivityResultId": "ab0e8400-e29b-41d4-a716-446655440000",
  "scheduledAt": "2025-01-16T09:00:00.000Z",
  "suggestedExecutionTime": null,
  "status": "READY",
  "idempotencyKey": "task-2025-01-15-001",
  "dispatchConfigId": null,
  "providerActivityId": null,
  "dispatchAttemptCount": 0,
  "errorCode": null,
  "errorMessage": null,
  "rawPayload": null,
  "createdAt": "2025-01-15T10:30:00.000Z",
  "updatedAt": "2025-01-15T10:30:00.000Z",
  "reasonConfig": {
    "id": "990e8400-e29b-41d4-a716-446655440000",
    "code": "monthly_visit",
    "label": "Visita Mensual",
    "intentCategory": "SALES",
    "isActive": true,
    "createdAt": "2024-12-01T12:00:00.000Z",
    "updatedAt": "2024-12-01T12:00:00.000Z"
  },
  "userStatusConfig": null,
  "commerceAssignment": {
    "activityId": "ee0e8400-e29b-41d4-a716-446655440000",
    "commerceId": "880e8400-e29b-41d4-a716-446655440000",
    "assignmentReason": null,
    "createdAt": "2025-01-15T10:30:00.000Z",
    "updatedAt": "2025-01-15T10:30:00.000Z",
    "commerce": {
      "id": "880e8400-e29b-41d4-a716-446655440000",
      "externalId": "STORE-001",
      "globalExternalId": null,
      "name": "Main Street Store",
      "taxId": null,
      "isPlaceholder": false,
      "isActive": true,
      "metadata": null,
      "createdAt": "2024-12-01T12:00:00.000Z",
      "updatedAt": "2024-12-01T12:00:00.000Z"
    }
  },
  "taskDetails": {
    "activityId": "ee0e8400-e29b-41d4-a716-446655440000",
    "assignedRouteId": "dd0e8400-e29b-41d4-a716-446655440000",
    "assignedOperatorId": "cc0e8400-e29b-41d4-a716-446655440000",
    "createdAt": "2025-01-15T10:30:00.000Z",
    "updatedAt": "2025-01-15T10:30:00.000Z",
    "assignedRoute": {
      "id": "dd0e8400-e29b-41d4-a716-446655440000",
      "code": "ZONE-NORTH",
      "name": "North Zone",
      "isPlaceholder": false,
      "isActive": true,
      "createdAt": "2024-12-01T12:00:00.000Z",
      "updatedAt": "2024-12-01T12:00:00.000Z"
    },
    "assignedOperator": {
      "id": "cc0e8400-e29b-41d4-a716-446655440000",
      "type": "SALESMAN",
      "externalId": "OP-001",
      "name": "John Doe",
      "email": "john.doe@example.com",
      "phone": null,
      "isPlaceholder": false,
      "isActive": true,
      "userId": null,
      "metadata": null,
      "createdAt": "2024-12-01T12:00:00.000Z",
      "updatedAt": "2024-12-01T12:00:00.000Z"
    }
  },
  "statusEvents": [
    {
      "id": "ff0e8400-e29b-41d4-a716-446655440001",
      "activityId": "ee0e8400-e29b-41d4-a716-446655440000",
      "fromStatus": null,
      "toStatus": "READY",
      "eventType": "CREATED",
      "errorCode": null,
      "errorMessage": null,
      "rawPayload": null,
      "occurredAt": "2025-01-15T10:30:00.000Z",
      "createdAt": "2025-01-15T10:30:00.000Z"
    }
  ],
  "reason": {
    "code": "monthly_visit",
    "label": "Visita Mensual"
  },
  "userStatus": null,
  "lifecycleStatus": null,
  "lifecycleStatusLabel": null,
  "lifecycleStatusDetail": null
}

The lifecycle* fields come back null in this response; Get Activity computes them.

originReasons returns the origin_reasons you sent, in the same order, and [] if you sent none.

originActivityResultId returns the origin_activity_result_id you sent, and null if you sent none. This response does not include the summary of that activity result; Get Activity returns it in originActivityResult.

Error Responses

StatusDescription
400Validation error: a missing or invalid field, or a field the endpoint does not accept
400origin_reasons is null, has more than 10 items, or has an invalid item: a code outside ^[a-z0-9_]+$ or longer than 100 characters, a description missing, empty, only spaces or longer than 500 characters, or a key besides code and description
400origin_activity_result_id is null or not a UUID
400form_id is null or not a UUID
400Neither commerce_id nor commerce_external_id — Se requiere al menos uno de los campos commerce_id o commerce_external_id.
400TASK without activity_details — TASK activities require activityDetails
400activity_details without a route or without an operator — assigned_route_id is required for TASK activities / assigned_operator_id is required for TASK activities
400The assigned route or operator is inactive — Assigned route is not active / Assigned operator is not active
400reason is not an active reason of the tenant's catalog, either unknown or deactivated — Activity reason "<code>" is not configured for this tenant
400The reason is context-dependent and the activity has no intent_category — Activity reason "<code>" has no default intent category; intent_category is required
400user_status is not an active code of the tenant's retention status catalog — User retention status "<code>" is not configured for this tenant
404origin_activity_result_id is not an activity result of the active project, either unknown or of another project — origin_activity_result_id: activity result "<id>" not found
404form_id is not a form of the active project or of the tenant, either unknown or of another project — No existe el formulario <id>. — code: ACTIVITY_FORM_NOT_FOUND
404commerce_id, assigned_route_id or assigned_operator_id does not exist — Commerce not found / Route not found / Operator not found
409The idempotency_key is already used by an activity of another project of the tenant — La clave de idempotencia ya está en uso.
409The form of form_id is of another category than the activity — El formulario <id> es de otra categoría que la gestión (SALES). — code: ACTIVITY_FORM_CATEGORY_MISMATCH
409form_id is omitted and neither the project nor the tenant has a default form of the category of the activity — No hay un formulario por defecto de la categoría SALES: indica uno o marca uno por defecto. — code: ACTIVITY_FORM_NOT_RESOLVED