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

# Crear campo

> Agrega una columna al esquema de un tablero.

Agrega un campo al esquema del tablero.

## Endpoint

```text theme={null}
POST /databases/{databaseId}/fields
```

## Body común

| Campo          | Tipo       | Requerido | Descripción                                                                |
| -------------- | ---------- | --------- | -------------------------------------------------------------------------- |
| `name`         | `string`   | Sí        | Nombre visible del campo.                                                  |
| `type`         | `string`   | Sí        | Tipo de dato.                                                              |
| `key`          | `string`   | No        | Clave estable para `values`; si la omites, se genera desde `name`.         |
| `required`     | `boolean`  | No        | Marca el campo como obligatorio en el esquema y en la captura del tablero. |
| `description`  | `string`   | No        | Ayuda para quien captura datos.                                            |
| `defaultValue` | Cualquiera | No        | Valor predeterminado para tipos compatibles.                               |

La `key` debe iniciar con una letra minúscula y usar `camelCase` o `snake_case`. Después de crear el campo, `key` y `type` son inmutables.

Cada `type` admite propiedades diferentes. Consulta [Tipos y configuración de campos](/tableros/tipos-de-campo) antes de construir el body.

## Ejemplo: campo de selección

```bash theme={null}
curl -X POST "https://api.insuranceboosters.com/api/v1/databases/{databaseId}/fields" \
  -H "Content-Type: application/json" \
  -H "x-ib-api-key: TU_API_KEY" \
  -d '{
    "name": "Estado",
    "key": "estado",
    "type": "enum",
    "required": true,
    "options": [
      { "label": "Vigente", "color": "green" },
      { "label": "Cancelada", "color": "red" }
    ]
  }'
```

## Respuesta exitosa (`201`)

Devuelve el campo creado con `id`, `key` y la configuración normalizada.

```json theme={null}
{
  "id": "<field-id>",
  "key": "estado",
  "name": "Estado",
  "type": "enum",
  "required": true,
  "options": [
    { "id": "vigente", "label": "Vigente", "color": "green", "order": 0 },
    { "id": "cancelada", "label": "Cancelada", "color": "red", "order": 1 }
  ]
}
```

## Errores frecuentes

| HTTP  | Qué significa                                 | Qué hacer                                    |
| ----- | --------------------------------------------- | -------------------------------------------- |
| `400` | Configuración inválida o incompleta.          | Revisa los campos requeridos para el `type`. |
| `403` | Tu integración no puede modificar el tablero. | Confirma el acceso al tablero.               |
| `404` | El tablero no existe.                         | Confirma `databaseId`.                       |


## OpenAPI

````yaml openapi/tableros-v1.yaml POST /databases/{databaseId}/fields
openapi: 3.1.0
info:
  title: Insurance Boosters API — Tableros
  version: 1.0.0
  description: API pública para administrar tableros, campos, registros y archivos.
  license:
    name: Propietaria
    url: https://insuranceboosters.com
servers:
  - url: https://api.insuranceboosters.com/api/v1
    description: Producción
security:
  - IbApiKey: []
tags:
  - name: Tableros
    description: Administración de tableros.
  - name: Campos
    description: Configuración del esquema de un tablero.
  - name: Registros
    description: Lectura y escritura de registros.
  - name: Archivos
    description: Archivos adjuntos a registros.
paths:
  /databases/{databaseId}/fields:
    parameters:
      - $ref: '#/components/parameters/DatabaseId'
    post:
      tags:
        - Campos
      summary: Crear campo
      operationId: createDatabaseField
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateFieldRequest'
            example:
              name: Estado
              key: estado
              type: enum
              required: true
              options:
                - label: Vigente
                  color: green
                - label: Cancelada
                  color: red
      responses:
        '201':
          description: Campo creado.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Field'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  parameters:
    DatabaseId:
      name: databaseId
      in: path
      required: true
      description: ID del tablero.
      schema:
        type: string
  schemas:
    CreateFieldRequest:
      allOf:
        - $ref: '#/components/schemas/FieldInputProperties'
        - type: object
          required:
            - name
            - type
      unevaluatedProperties: false
    Field:
      allOf:
        - $ref: '#/components/schemas/FieldInputProperties'
        - type: object
          required:
            - id
            - key
            - name
            - type
          properties:
            id:
              type: string
            inverseFieldId:
              type: string
            relationPairId:
              type: string
    FieldInputProperties:
      type: object
      properties:
        name:
          type: string
          minLength: 1
          description: Nombre visible del campo.
        key:
          type: string
          pattern: ^[a-z][a-zA-Z0-9]*(?:_[a-z0-9]+)*$
          description: Clave estable; se genera desde `name` si la omites.
        type:
          type: string
          enum:
            - string
            - number
            - boolean
            - date
            - enum
            - enum_multi
            - relation_single
            - relation_multi
            - contact_single
            - contact_multi
            - lookup
            - files
          description: Tipo inmutable después de crear el campo.
        required:
          type: boolean
          default: false
          description: >-
            Marca el campo como obligatorio en el esquema y en la captura del
            tablero.
        description:
          type: string
        defaultValue:
          description: Valor predeterminado para tipos compatibles.
        dateConfig:
          allOf:
            - $ref: '#/components/schemas/DateConfig'
          description: Configuración de presentación cuando `type` es `date`.
        options:
          type: array
          minItems: 1
          description: Requerido para `enum` y `enum_multi`.
          items:
            $ref: '#/components/schemas/EnumOptionInput'
        toDatabaseId:
          type: string
          description: Requerido para campos de relación.
        displayFieldId:
          type: string
          description: Campo mostrado en relaciones o contactos.
        bidirectional:
          type: boolean
          default: false
        inverseField:
          $ref: '#/components/schemas/InverseFieldInput'
        relationFieldId:
          type: string
          description: Requerido para `lookup`.
        targetFieldId:
          type: string
          description: Requerido para `lookup`.
        multipleValuesBehavior:
          type: string
          enum:
            - allValues
            - uniqueValues
            - firstValue
            - lastValue
          description: Requerido para `lookup`.
        maxFiles:
          type: integer
          minimum: 1
          description: Máximo de archivos cuando `type` es `files`.
        accept:
          type: array
          description: Tipos MIME aceptados cuando `type` es `files`.
          items:
            type: string
        numberFormat:
          $ref: '#/components/schemas/NumberFormat'
    Error:
      type: object
      properties:
        message:
          type: string
        error:
          type: string
      additionalProperties: false
    DateConfig:
      type: object
      additionalProperties: false
      required:
        - includeTime
      properties:
        includeTime:
          type: boolean
          default: false
          description: >-
            Controla si el tablero captura y muestra hora. No cambia la
            validación del valor.
    EnumOptionInput:
      type: object
      additionalProperties: false
      required:
        - label
      properties:
        id:
          type: string
          description: ID estable; se genera automáticamente si lo omites.
        label:
          type: string
          minLength: 1
        color:
          type: string
        order:
          type: integer
          minimum: 0
    InverseFieldInput:
      type: object
      additionalProperties: false
      description: >-
        Vincula un campo existente con `id` o crea uno nuevo con `name` y
        `type`.
      properties:
        id:
          type: string
          description: ID de un campo de relación existente en el tablero destino.
        name:
          type: string
          minLength: 1
          description: Nombre de un campo inverso nuevo.
        key:
          type: string
          pattern: ^[a-z][a-zA-Z0-9]*(?:_[a-z0-9]+)*$
        type:
          type: string
          enum:
            - relation_single
            - relation_multi
        displayFieldId:
          type: string
    NumberFormat:
      type: object
      additionalProperties: false
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - none
            - currency
            - percent
          description: Formato visual del número.
        currencyCode:
          type: string
          enum:
            - USD
            - EUR
            - MXN
            - BRL
            - ARS
            - COP
            - CLP
            - PEN
            - UYU
            - GTQ
          description: Requerido cuando `type` es `currency`.
        decimalPlaces:
          type: integer
          minimum: 0
          maximum: 6
          default: 2
        thousandsSeparator:
          type: boolean
          default: true
  responses:
    BadRequest:
      description: Solicitud inválida.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: API key inválida o faltante.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Forbidden:
      description: La integración no tiene acceso al recurso.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: Recurso no encontrado.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    InternalError:
      description: Error del servicio.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    IbApiKey:
      type: apiKey
      in: header
      name: x-ib-api-key
      description: API key de Insurance Boosters.

````