# custom_objects.relation_update

Editar ligação. Renomeia os dois lados, liga ou desliga `showOnCard` (só com Oportunidades) e muda `cardinality` — esta só enquanto a ligação não tem vínculos (senão `invalid_input` com a contagem). Os dois lados da outra ponta não mudam.

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

## Entrada

| Campo | Tipo | Obrigatório | Nota |
|---|---|---|---|
| `cardinality` | "many_to_one" \| "one_to_many" \| "many_to_many" | não |  |
| `sourceLabel` | string | não |  |
| `targetLabel` | string | não |  |
| `showOnCard` | boolean | não |  |
| `id` | string (uuid) | sim |  |

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

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "cardinality": {
      "type": "string",
      "enum": [
        "many_to_one",
        "one_to_many",
        "many_to_many"
      ]
    },
    "sourceLabel": {
      "type": "string",
      "minLength": 1,
      "maxLength": 60
    },
    "targetLabel": {
      "type": "string",
      "minLength": 1,
      "maxLength": 60
    },
    "showOnCard": {
      "type": "boolean"
    },
    "id": {
      "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": [
    "id"
  ]
}
```

</details>

## Exemplo

```bash
curl -X POST https://app.atomiks.com.br/api/v1/custom_objects.relation_update \
  -H "Authorization: Bearer $ATOMIKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"id":"00000000-0000-0000-0000-000000000000","sourceLabel":"Dono","targetLabel":"Imóveis do dono"}'
```

CLI:

```bash
node cli/atomiks.mjs custom_objects.relation_update --json '{"id":"00000000-0000-0000-0000-000000000000","sourceLabel":"Dono","targetLabel":"Imóveis do dono"}'
```

MCP: ferramenta `custom_objects_relation_update` 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": {
    "id": {
      "type": "string"
    },
    "objectId": {
      "type": "string"
    },
    "sourceObject": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "singularName": {
          "type": "string"
        },
        "pluralName": {
          "type": "string"
        },
        "icon": {
          "type": "string"
        },
        "color": {
          "type": "string"
        },
        "gender": {
          "type": "string",
          "enum": [
            "masculine",
            "feminine"
          ]
        }
      },
      "required": [
        "id",
        "singularName",
        "pluralName",
        "icon",
        "color",
        "gender"
      ],
      "additionalProperties": false
    },
    "sourceLabel": {
      "type": "string"
    },
    "targetLabel": {
      "type": "string"
    },
    "targetType": {
      "type": "string",
      "enum": [
        "leads",
        "opportunities",
        "companies",
        "objects"
      ]
    },
    "targetObjectId": {
      "type": [
        "string",
        "null"
      ]
    },
    "targetObject": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "singularName": {
              "type": "string"
            },
            "pluralName": {
              "type": "string"
            },
            "icon": {
              "type": "string"
            },
            "color": {
              "type": "string"
            },
            "gender": {
              "type": "string",
              "enum": [
                "masculine",
                "feminine"
              ]
            }
          },
          "required": [
            "id",
            "singularName",
            "pluralName",
            "icon",
            "color",
            "gender"
          ],
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ]
    },
    "cardinality": {
      "type": "string",
      "enum": [
        "many_to_one",
        "one_to_many",
        "many_to_many"
      ]
    },
    "showOnCard": {
      "type": "boolean"
    },
    "linkCount": {
      "type": "number"
    },
    "createdAt": {
      "type": "string"
    },
    "updatedAt": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "objectId",
    "sourceObject",
    "sourceLabel",
    "targetLabel",
    "targetType",
    "targetObjectId",
    "targetObject",
    "cardinality",
    "showOnCard",
    "linkCount",
    "createdAt",
    "updatedAt"
  ],
  "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).
