> ## 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/tickets/:id/stage

> Move a ticket to another stage of its pipeline and read back what the transition triggered.

Moves a ticket to a different stage. This is the endpoint to use for pipeline transitions — it runs the pipeline's own rules and reports what the move triggered, which a plain field write through [`PATCH /v1/crm/tickets/:id`](/dev/endpoints/crm-ticket-update) does not.

The optional context fields (`prioridad`, `contexto`, `problema`, `recomendaciones`) are recorded with the transition and surfaced to whoever picks the ticket up next. They are especially useful when an automation hands a ticket over to a human stage.

## Endpoint

```
POST https://api.keebai.com/v1/crm/tickets/{id}/stage
```

## Required scope

`crm:tickets:write`

## Headers

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

## Path parameters

| Field | Type     | Required | Description               |
| ----- | -------- | -------- | ------------------------- |
| `id`  | `string` | Yes      | `ObjectId` of the ticket. |

## Body

| Field             | Type     | Required | Description                                  |
| ----------------- | -------- | -------- | -------------------------------------------- |
| `stage_id`        | `string` | Yes      | `ObjectId` of the destination stage.         |
| `prioridad`       | `string` | No       | Priority reported with the handover.         |
| `contexto`        | `string` | No       | Context for whoever handles the ticket next. |
| `problema`        | `string` | No       | The problem detected.                        |
| `recomendaciones` | `string` | No       | Recommended next actions.                    |

## Example request

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://api.keebai.com/v1/crm/tickets/65f4b5c6d7e8f9a0b1c2d3e4/stage \
    -H "Authorization: Bearer kbai_pk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
    -H "Content-Type: application/json" \
    -d '{
      "stage_id": "67d1e2f3a4b5c6d7e8f9a0b1",
      "prioridad": "alta",
      "contexto": "Cliente pidió hablar con un ejecutivo",
      "recomendaciones": "Llamar antes de las 18:00"
    }'
  ```

  ```js JavaScript theme={null}
  const response = await fetch(
    `https://api.keebai.com/v1/crm/tickets/${ticketId}/stage`,
    {
      method: "POST",
      headers: {
        Authorization: `Bearer ${process.env.KEEBAI_API_TOKEN}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        stage_id: humanStageId,
        contexto: "Cliente pidió hablar con un ejecutivo",
      }),
    },
  );
  const { stage_changed, is_human_stage } = await response.json();
  ```

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

  resp = requests.post(
      f"https://api.keebai.com/v1/crm/tickets/{ticket_id}/stage",
      headers={"Authorization": f"Bearer {os.environ['KEEBAI_API_TOKEN']}"},
      json={
          "stage_id": human_stage_id,
          "contexto": "Cliente pidió hablar con un ejecutivo",
      },
      timeout=10,
  )
  resp.raise_for_status()
  result = resp.json()
  ```
</CodeGroup>

## Response

### 200 OK

```json theme={null}
{
  "ticket": {
    "_id": "65f4b5c6d7e8f9a0b1c2d3e4",
    "stage": "67d1e2f3a4b5c6d7e8f9a0b1",
    "updated_at": "2026-05-02T16:22:03.812Z"
  },
  "previous_stage_id": "66c1d2e3f4a5b6c7d8e9f0a1",
  "current_stage_id": "67d1e2f3a4b5c6d7e8f9a0b1",
  "stage_changed": true,
  "is_human_stage": true,
  "stage_type": "human",
  "next_stage_to_set": null
}
```

| Field               | Meaning                                                                                                  |
| ------------------- | -------------------------------------------------------------------------------------------------------- |
| `stage_changed`     | `false` when the ticket was already in that stage — the call is idempotent.                              |
| `is_human_stage`    | `true` when the destination stage expects a human, which is how you detect a handover out of automation. |
| `stage_type`        | The stage's configured type.                                                                             |
| `next_stage_to_set` | Set when the pipeline's rules want the ticket to advance again; `null` otherwise.                        |

### 400 Bad Request

Missing or malformed `stage_id`, or a property the endpoint does not accept.

### 401 Unauthorized

Missing, invalid, revoked, or expired token.

### 403 Forbidden

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

### 404 Not Found

No ticket with that id, or the ticket belongs to a different company.

## Operational notes

* **Moving to the current stage is a no-op** that returns `200` with `stage_changed: false`. Safe to retry.
* **Watch `is_human_stage`** if your automation must stop talking once a person takes over the conversation.
* **Stage ids are opaque.** There is no public endpoint for listing pipelines and stages yet — read them from the portal, or capture them from the `stage` field of tickets you already fetched.


## OpenAPI

````yaml POST /v1/crm/tickets/{id}/stage
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/tickets/{id}/stage:
    post:
      tags:
        - crm-tickets
      summary: Mover un ticket de etapa
      description: >-
        Mueve el ticket a la etapa indicada dentro de su pipeline y devuelve el
        estado resultante.
      operationId: PublicTicketsController_moveStage
      parameters:
        - name: id
          required: true
          in: path
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PublicTicketStageDto'
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicTicketStageChangeResponseDto'
      security:
        - PAT: []
components:
  schemas:
    PublicTicketStageDto:
      type: object
      properties:
        stage_id:
          type: string
          description: Etapa de destino dentro del pipeline
        prioridad:
          type: string
          description: Prioridad reportada al mover la etapa
        contexto:
          type: string
          description: Contexto del movimiento
        problema:
          type: string
          description: Problema detectado
        recomendaciones:
          type: string
          description: Recomendaciones para el operador
      required:
        - stage_id
    PublicTicketStageChangeResponseDto:
      type: object
      properties:
        ticket:
          $ref: '#/components/schemas/PublicTicketResponseDto'
        previous_stage_id:
          type: string
          description: Etapa previa al movimiento
        current_stage_id:
          type: string
          description: Etapa resultante
        stage_changed:
          type: boolean
          description: false si el ticket ya estaba en esa etapa; la llamada es idempotente
        is_human_stage:
          type: boolean
          description: La etapa de destino espera intervención de una persona
        stage_type:
          type: string
        next_stage_to_set:
          type: string
          description: Presente cuando las reglas del pipeline piden avanzar de nuevo
      required:
        - ticket
        - current_stage_id
        - stage_changed
    PublicTicketResponseDto:
      type: object
      properties:
        _id:
          type: string
          description: ObjectId del ticket
        chat_user:
          type: string
          description: ObjectId del chat user (contacto)
        chat_user_name:
          type: string
        chat_user_avatar:
          type: string
        chat_user_channel:
          type: string
          description: Canal de origen (whatsapp, instagram…)
        chat_user_channel_id:
          type: string
        stage:
          description: Etapa actual del pipeline. Ausente si el ticket no tiene una.
          allOf:
            - $ref: '#/components/schemas/PublicTicketStageDto'
        is_closed:
          type: boolean
        resolution:
          type: string
          enum:
            - won
            - lost
        priority:
          type: string
          enum:
            - low
            - medium
            - high
            - urgent
        category:
          type: string
        assigned_to:
          $ref: '#/components/schemas/PublicTicketAssigneeDto'
        tags:
          type: array
          items:
            $ref: '#/components/schemas/PublicTicketTagDto'
        custom_fields:
          type: object
        amount:
          type: number
        amount_currency:
          type: string
          description: Moneda ISO 4217
        amount_status:
          type: string
          enum:
            - estimated
            - confirmed
        conversation_summary:
          $ref: '#/components/schemas/PublicConversationSummaryDto'
        ai_feedback_status:
          type: string
          description: 'Feedback de la IA: resolved | unresolved'
        appointment_ids:
          description: Citas de scheduling vinculadas al ticket
          type: array
          items:
            type: string
        last_message:
          description: Último mensaje del contacto. Sólo presente en el listado.
          allOf:
            - $ref: '#/components/schemas/PublicTicketLastMessageDto'
        closed_at:
          type: string
          format: date-time
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
      required:
        - _id
        - chat_user
        - is_closed
        - priority
        - tags
        - custom_fields
        - created_at
        - updated_at
    PublicTicketAssigneeDto:
      type: object
      properties:
        id:
          type: string
          description: ObjectId del usuario
        full_name:
          type: string
        email:
          type: string
      required:
        - id
    PublicTicketTagDto:
      type: object
      properties:
        id:
          type: string
          description: ObjectId del tag
        name:
          type: string
        color:
          type: string
          description: 'Color hex, ej. #1890ff'
      required:
        - id
        - name
    PublicConversationSummaryDto:
      type: object
      properties:
        motivo:
          type: string
        estado:
          type: string
        proximos_pasos:
          type: string
        is_final:
          type: boolean
    PublicTicketLastMessageDto:
      type: object
      properties:
        id:
          type: string
        content:
          type: string
        role:
          type: string
        direction:
          type: string
          description: inbound | outbound
        created_at:
          type: string
          format: date-time
      required:
        - id
  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`.

````