# custom_fields.values_set

Gravar valores de campos customizados de uma oportunidade. Lista de `{fieldId, value}` (até 50); `value: null` limpa, exceto em campo obrigatório. Cada valor é validado pelo tipo do campo (texto, número, data `AAAA-MM-DD`, opção, lista de opções, link, 1 a 5, sim/não, id de arquivo). Tudo ou nada: um valor inválido recusa o pedido. Devolve os campos ativos com os valores, como `custom_fields.values_get`. `unique` ainda não é verificado na gravação.

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

## Entrada

| Campo | Tipo | Obrigatório | Nota |
|---|---|---|---|
| `entity` | "opportunity" | sim |  |
| `id` | string (uuid) | sim |  |
| `values` | object[] | sim |  |
| `source` | "manual" \| "import" \| "form" \| "booking" \| "webchat" \| "flow" \| "api" | não |  |

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

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "entity": {
      "type": "string",
      "const": "opportunity"
    },
    "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)$"
    },
    "values": {
      "minItems": 1,
      "maxItems": 50,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "fieldId": {
            "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)$"
          },
          "value": {
            "anyOf": [
              {},
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "fieldId",
          "value"
        ]
      }
    },
    "source": {
      "type": "string",
      "enum": [
        "manual",
        "import",
        "form",
        "booking",
        "webchat",
        "flow",
        "api"
      ]
    }
  },
  "required": [
    "entity",
    "id",
    "values"
  ]
}
```

</details>

## Exemplo

```bash
curl -X POST https://app.atomiks.com.br/api/v1/custom_fields.values_set \
  -H "Authorization: Bearer $ATOMIKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"entity":"opportunity","id":"00000000-0000-0000-0000-000000000000","values":[{"fieldId":"00000000-0000-0000-0000-000000000000","value":"Mentoria"}]}'
```

CLI:

```bash
node cli/atomiks.mjs custom_fields.values_set --json '{"entity":"opportunity","id":"00000000-0000-0000-0000-000000000000","values":[{"fieldId":"00000000-0000-0000-0000-000000000000","value":"Mentoria"}]}'
```

MCP: ferramenta `custom_fields_values_set` 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": {
    "customFields": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "fieldName": {
            "type": "string"
          },
          "displayName": {
            "type": "string"
          },
          "fieldType": {
            "type": "string",
            "enum": [
              "text",
              "textarea",
              "number",
              "currency",
              "percentage",
              "date",
              "select",
              "multi_select",
              "radio",
              "link",
              "rating",
              "boolean",
              "file",
              "image"
            ]
          },
          "options": {
            "anyOf": [
              {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "label": {
                      "type": "string"
                    },
                    "value": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "label",
                    "value"
                  ],
                  "additionalProperties": false
                }
              },
              {
                "type": "null"
              }
            ]
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "groupName": {
            "type": [
              "string",
              "null"
            ]
          },
          "required": {
            "type": "boolean"
          },
          "pinned": {
            "type": "boolean"
          },
          "position": {
            "type": "number"
          },
          "value": {
            "anyOf": [
              {},
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "id",
          "fieldName",
          "displayName",
          "fieldType",
          "options",
          "description",
          "groupName",
          "required",
          "pinned",
          "position",
          "value"
        ],
        "additionalProperties": false
      }
    }
  },
  "required": [
    "customFields"
  ],
  "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).
