> ## 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.

# Vincular relación bidireccional

> Conecta dos campos de relación existentes como un par bidireccional.

Vincula un campo `relation_single` o `relation_multi` con un campo compatible del tablero destino. A partir de ese momento, ambos lados se mantienen como un par.

<Note>
  Puedes vincular `relation_single` con `relation_single` o `relation_multi`. No puedes vincular dos campos `relation_multi`.
</Note>

## Endpoint

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

## Body

| Campo            | Tipo     | Requerido | Descripción                                               |
| ---------------- | -------- | --------- | --------------------------------------------------------- |
| `inverseFieldId` | `string` | Sí        | ID del campo de relación existente en el tablero destino. |

## Ejemplo de solicitud

```bash theme={null}
curl -X POST "https://api.insuranceboosters.com/api/v1/databases/{databaseId}/fields/{fieldId}/link" \
  -H "Content-Type: application/json" \
  -H "x-ib-api-key: TU_API_KEY" \
  -d '{ "inverseFieldId": "<inverse-field-id>" }'
```

## Respuesta exitosa (`200`)

```json theme={null}
{
  "sourceField": {
    "id": "<field-id>",
    "type": "relation_single",
    "bidirectional": true,
    "inverseFieldId": "<inverse-field-id>"
  },
  "inverseField": {
    "id": "<inverse-field-id>",
    "type": "relation_multi",
    "bidirectional": true,
    "inverseFieldId": "<field-id>"
  }
}
```

## Errores frecuentes

| HTTP  | Qué significa                                                                     | Qué hacer                                   |
| ----- | --------------------------------------------------------------------------------- | ------------------------------------------- |
| `400` | Falta `inverseFieldId`, los campos no son compatibles o alguno ya está vinculado. | Revisa ambos campos y sus tableros destino. |
| `403` | Tu integración no puede modificar uno de los tableros.                            | Confirma el acceso.                         |
| `404` | El tablero o un campo no existe.                                                  | Confirma los IDs.                           |


## OpenAPI

````yaml openapi/tableros-v1.yaml POST /databases/{databaseId}/fields/{fieldId}/link
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/{fieldId}/link:
    parameters:
      - $ref: '#/components/parameters/DatabaseId'
      - $ref: '#/components/parameters/FieldId'
    post:
      tags:
        - Campos
      summary: Vincular relación
      operationId: linkRelationField
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required:
                - inverseFieldId
              properties:
                inverseFieldId:
                  type: string
                  minLength: 1
                  description: >-
                    ID de un campo compatible en el tablero destino. No se
                    admite vincular dos campos `relation_multi`.
            example:
              inverseFieldId: <inverse-field-id>
      responses:
        '200':
          description: Relación vinculada.
          content:
            application/json:
              schema:
                type: object
                required:
                  - sourceField
                  - inverseField
                properties:
                  sourceField:
                    $ref: '#/components/schemas/Field'
                  inverseField:
                    $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
    FieldId:
      name: fieldId
      in: path
      required: true
      description: ID inmutable del campo.
      schema:
        type: string
  schemas:
    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.

````