> ## 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/tags

> Add a tag to the catalog, for tickets or for customers.

Creates a tag. The `scope` decides what it labels: `ticket` for pipeline tickets, `client` for customers and contacts. It cannot change later.

The `company` and `project` are taken from your token and must **not** appear in the body. Sending them returns `400`.

> [!TIP]
>
> A tag name is unique per scope. Before creating, [list the tags](https://docs.keebai.com/dev/endpoints/crm-tags-list.md) with `search` and reuse the one that already exists — that keeps reports grouped under a single tag.

## Endpoint

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

## Required scope

`crm:tags:write`

## Headers

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

## Body

| Field | Type | Required | Description |
| - | - | - | - |
| `name` | `string` | Yes | Tag name. Up to 100 characters. Unique per scope within the company. |
| `scope` | `string` | Yes | `ticket` or `client`. |
| `color` | `string` | No | Hex color shown in the portal. Defaults to `#1890ff`. |
| `category_id` | `string` | No | `ObjectId` of a [tag category](https://docs.keebai.com/dev/endpoints/crm-tag-categories-list.md) of the same scope. |

## Example request

```bash curl theme={"system"}
curl -X POST https://api.keebai.com/v1/crm/tags \
  -H "Authorization: Bearer kbai_pk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Cliente VIP",
    "scope": "ticket",
    "color": "#f5a623",
    "category_id": "6720a0f1e2d3c4b5a6978877"
  }'
```

```js JavaScript theme={"system"}
const response = await fetch("https://api.keebai.com/v1/crm/tags", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KEEBAI_API_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ name: "Cliente VIP", scope: "ticket", color: "#f5a623" }),
});
const { tag } = await response.json();
```

```python Python theme={"system"}
import os, requests

resp = requests.post(
    "https://api.keebai.com/v1/crm/tags",
    headers={"Authorization": f"Bearer {os.environ['KEEBAI_API_TOKEN']}"},
    json={"name": "Cliente VIP", "scope": "ticket", "color": "#f5a623"},
    timeout=10,
)
resp.raise_for_status()
tag = resp.json()["tag"]
```

## Response

### 201 Created

```json theme={"system"}
{
  "tag": {
    "_id": "6720a1b2c3d4e5f6a7b8c9d0",
    "name": "Cliente VIP",
    "color": "#f5a623",
    "scope": "ticket",
    "category_id": "6720a0f1e2d3c4b5a6978877",
    "created_at": "2026-10-02T13:04:11.512Z",
    "updated_at": "2026-10-02T13:04:11.512Z"
  }
}
```

### 400 Bad Request

* A tag with the same `name` already exists in that scope (`Tag name already exists for this scope`).
* The category belongs to the other scope (`Tag scope must match its category scope`).
* Missing `name` or `scope`, a `scope` outside the allowed set, a malformed `category_id`, or a property the endpoint does not accept — including `company` and `project`, which are derived from the token.

### 401 Unauthorized

Missing, invalid, revoked, or expired token.

### 403 Forbidden

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

### 404 Not Found

`category_id` does not match a category of your company (`Tag category not found`).

## Operational notes

* **Name uniqueness is an exact match.** `VIP` and `vip` are different names to this endpoint. Normalize names on your side before creating if your source system is loose about casing.


## OpenAPI

````yaml POST /v1/crm/tags
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/tags:
    post:
      tags:
        - crm-tags
      summary: Crear una etiqueta
      description: >-
        La company y el project se toman del token; enviarlos en el body
        devuelve 400. Un nombre que ya existe en el mismo scope devuelve 400.
      operationId: PublicTagsController_create
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PublicTagCreateDto'
      responses:
        '201':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicTagEnvelopeDto'
      security:
        - PAT: []
components:
  schemas:
    PublicTagCreateDto:
      type: object
      properties:
        name:
          type: string
          description: >-
            Nombre de la etiqueta. Único por scope dentro de la company
            (coincidencia exacta).
        scope:
          type: string
          enum:
            - ticket
            - client
          description: >-
            `ticket` etiqueta tickets del pipeline; `client` etiqueta clientes y
            contactos.
        color:
          type: string
          description: Color hexadecimal. Por defecto `#1890ff`.
          example: '#1890ff'
        category_id:
          type: string
          description: >-
            Categoría de la etiqueta. Debe existir y ser del mismo scope que la
            etiqueta.
      required:
        - name
        - scope
    PublicTagEnvelopeDto:
      type: object
      properties:
        tag:
          $ref: '#/components/schemas/PublicTagResponseDto'
      required:
        - tag
    PublicTagResponseDto:
      type: object
      properties:
        _id:
          type: string
          description: ObjectId de la etiqueta
        name:
          type: string
        color:
          type: string
          example: '#1890ff'
        scope:
          type: string
          enum:
            - ticket
            - client
        category_id:
          type: string
          nullable: true
          description: ObjectId de la categoría, o `null` si no tiene.
        category:
          nullable: true
          description: >-
            Resumen de la categoría. Sólo viene en el listado; el detalle trae
            `category_id`.
          type: object
          allOf:
            - $ref: '#/components/schemas/PublicTagCategorySummaryDto'
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
      required:
        - _id
        - name
        - color
        - scope
        - category_id
        - created_at
        - updated_at
    PublicTagCategorySummaryDto:
      type: object
      properties:
        id:
          type: string
          description: ObjectId de la categoría
        name:
          type: string
        exclusive:
          type: boolean
      required:
        - id
        - name
        - exclusive
  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`.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.