> ## Documentation Index
> Fetch the complete documentation index at: https://docs.keebai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# POST /v1/crm/tasks

> Create a task with an optional assignee, due date, and priority.

Creates a task. Only `title` is mandatory.

The `company` is taken from your token and must **not** appear in the body. Sending it returns `400`. Unlike customers, tickets, and notes, tasks carry no `project` — they are company-level records.

## Endpoint

```
POST https://api.keebai.com/v1/crm/tasks
```

## Required scope

`crm:tasks:write`

## Headers

| Header          | Required | Value                    |
| --------------- | -------- | ------------------------ |
| `Authorization` | Yes      | `Bearer kbai_pk_<token>` |
| `Content-Type`  | Yes      | `application/json`       |

## Body

| Field         | Type     | Required | Description                                                     |
| ------------- | -------- | -------- | --------------------------------------------------------------- |
| `title`       | `string` | Yes      | What has to be done. Up to 500 characters.                      |
| `description` | `string` | No       | Longer detail. Up to 5000 characters.                           |
| `assigned_to` | `string` | No       | `ObjectId` of the user responsible.                             |
| `status`      | `string` | No       | Free-form status. Defaults to `pending`.                        |
| `priority`    | `string` | No       | One of `low`, `medium`, `high`, `urgent`. Defaults to `medium`. |
| `due_at`      | `string` | No       | Due date in ISO 8601, e.g. `2026-05-05T13:00:00Z`.              |

## Example request

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://api.keebai.com/v1/crm/tasks \
    -H "Authorization: Bearer kbai_pk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
    -H "Content-Type: application/json" \
    -d '{
      "title": "Llamar a Juan Pérez",
      "description": "Confirmar propuesta del plan anual",
      "assigned_to": "68e1f2a3b4c5d6e7f8a9b0c1",
      "priority": "high",
      "due_at": "2026-05-05T13:00:00Z"
    }'
  ```

  ```js JavaScript theme={null}
  const response = await fetch("https://api.keebai.com/v1/crm/tasks", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.KEEBAI_API_TOKEN}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      title: "Llamar a Juan Pérez",
      assigned_to: userId,
      priority: "high",
      due_at: dueDate.toISOString(),
    }),
  });
  const { task } = await response.json();
  ```

  ```python Python theme={null}
  import os, requests

  resp = requests.post(
      "https://api.keebai.com/v1/crm/tasks",
      headers={"Authorization": f"Bearer {os.environ['KEEBAI_API_TOKEN']}"},
      json={
          "title": "Llamar a Juan Pérez",
          "assigned_to": user_id,
          "priority": "high",
          "due_at": "2026-05-05T13:00:00Z",
      },
      timeout=10,
  )
  resp.raise_for_status()
  task = resp.json()["task"]
  ```
</CodeGroup>

## Response

### 201 Created

```json theme={null}
{
  "task": {
    "_id": "65a1f2b3c4d5e6f7a8b9c0d1",
    "title": "Llamar a Juan Pérez",
    "description": "Confirmar propuesta del plan anual",
    "status": "pending",
    "priority": "high",
    "assigned_to": "68e1f2a3b4c5d6e7f8a9b0c1",
    "due_at": "2026-05-05T13:00:00.000Z",
    "created_at": "2026-05-02T14:31:07.221Z",
    "updated_at": "2026-05-02T14:31:07.221Z"
  }
}
```

### 400 Bad Request

Missing `title`, a `due_at` that is not valid ISO 8601, a `priority` outside the allowed set, or a property the endpoint does not accept — including `company`, which is derived from the token.

### 401 Unauthorized

Missing, invalid, revoked, or expired token.

### 403 Forbidden

The token does not have the `crm:tasks:write` scope.

## Operational notes

* **Tasks stand alone.** There is no field linking a task to a ticket or a customer. Put the related id in the `description` if your workflow needs the association.
* **`due_at` is stored as an instant, not a calendar day.** Send an explicit timezone offset (or `Z`) so a due date does not shift for users in `America/Santiago`.


## OpenAPI

````yaml POST /v1/crm/tasks
openapi: 3.0.0
info:
  title: Keebai Public API
  description: Superficie pública REST autenticada con Personal Access Tokens (PAT).
  version: 1.0.0
  contact: {}
servers:
  - url: https://api.keebai.com
    description: Production
security: []
tags: []
paths:
  /v1/crm/tasks:
    post:
      tags:
        - crm-tasks
      summary: Crear una tarea
      description: La company se toma del token; enviarla en el body devuelve 400.
      operationId: PublicTasksController_create
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PublicTaskCreateDto'
      responses:
        '201':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicTaskEnvelopeDto'
      security:
        - PAT: []
components:
  schemas:
    PublicTaskCreateDto:
      type: object
      properties:
        title:
          type: string
          description: Título de la tarea
        assigned_to:
          type: string
          description: Id del usuario asignado
        status:
          type: string
          description: >-
            Estado libre. Los valores del portal son pending, in_progress,
            completed y cancelled.
          default: pending
        priority:
          type: string
          enum:
            - low
            - medium
            - high
            - urgent
          default: medium
        due_at:
          type: string
          description: Vencimiento en ISO 8601
        description:
          type: string
      required:
        - title
    PublicTaskEnvelopeDto:
      type: object
      properties:
        task:
          $ref: '#/components/schemas/PublicTaskResponseDto'
      required:
        - task
    PublicTaskResponseDto:
      type: object
      properties:
        _id:
          type: string
          description: ObjectId de la tarea
        title:
          type: string
        description:
          type: string
        status:
          type: string
          description: >-
            Estado libre. Los valores del portal son pending, in_progress,
            completed y cancelled.
        priority:
          type: string
          enum:
            - low
            - medium
            - high
            - urgent
        assigned_to:
          type: string
          description: ObjectId del usuario asignado
        due_at:
          type: string
          format: date-time
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
      required:
        - _id
        - title
        - status
        - priority
        - created_at
        - updated_at
  securitySchemes:
    PAT:
      scheme: bearer
      bearerFormat: kbai_pk_<hex>
      type: http
      description: >-
        Personal Access Token con prefijo `kbai_pk_`. Generar desde el portal
        con permiso `developer.manage_tokens`.

````