# custom_objects.link_create

Vincular registros. Cria vínculos de uma ligação: `relationId` e `links` (`{recordId, targetId}`: `recordId` é o registro da origem — do objeto dono da ligação — e `targetId` o contato, oportunidade, empresa ou registro do outro lado). Lado "um" da cardinalidade guarda um vínculo só: ligar de novo troca o anterior (`replaced` conta as trocas). Vínculo que já existe é ignorado. Objetos arquivados não recebem vínculos.

- Endpoint: `POST https://app.atomiks.com.br/api/v1/custom_objects.link_create` (corpo JSON)
- Quem pode chamar: membro da conta
- Escopo da chave: `crm:write`
- Grava dados: sim
- Pela chave de API: sim
- Ferramenta MCP: `custom_objects_link_create`
- Ficha em JSON: `https://app.atomiks.com.br/api/v1/openapi.json` (operationId `custom_objects.link_create`)

## Entrada

| Campo | Tipo | Obrigatório | Nota |
|---|---|---|---|
| `relationId` | string (uuid) | sim |  |
| `links` | object[] | sim |  |

<details><summary>JSON Schema</summary>

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "relationId": {
      "type": "string",
      "format": "uuid",
      "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
    },
    "links": {
      "minItems": 1,
      "maxItems": 200,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "recordId": {
            "type": "string",
            "format": "uuid",
            "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
          },
          "targetId": {
            "type": "string",
            "format": "uuid",
            "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
          }
        },
        "required": [
          "recordId",
          "targetId"
        ]
      }
    }
  },
  "required": [
    "relationId",
    "links"
  ]
}
```

</details>

## Exemplo

```bash
curl -X POST https://app.atomiks.com.br/api/v1/custom_objects.link_create \
  -H "Authorization: Bearer $ATOMIKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"relationId":"00000000-0000-0000-0000-000000000000","links":[{"recordId":"00000000-0000-0000-0000-000000000000","targetId":"00000000-0000-0000-0000-000000000000"}]}'
```

CLI:

```bash
node cli/atomiks.mjs custom_objects.link_create --json '{"relationId":"00000000-0000-0000-0000-000000000000","links":[{"recordId":"00000000-0000-0000-0000-000000000000","targetId":"00000000-0000-0000-0000-000000000000"}]}'
```

MCP: ferramenta `custom_objects_link_create` com a mesma entrada.

## Saída

Sucesso: `{"data": ...}` com o formato abaixo.

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "items": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "relationId": {
            "type": "string"
          },
          "recordId": {
            "type": "string"
          },
          "targetId": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "relationId",
          "recordId",
          "targetId"
        ],
        "additionalProperties": false
      }
    },
    "replaced": {
      "type": "number"
    }
  },
  "required": [
    "items",
    "replaced"
  ],
  "additionalProperties": false
}
```

## Erros

`{"error": {"code", "message", "requestId"}}`. Códigos: `invalid_input` (400), `unauthorized` (401), `forbidden` / `account_pending` / `scope_missing` (403), `not_found` (404), `limit_reached` (409), `internal` (500).
