# crm.task_create

Criar tarefa. Tarefa de um contato. `assigneeId` precisa ser membro que veja o contato. `kind: meeting` exige `opportunityId`. `notes` é HTML (negrito, itálico, listas, H1-H3): o servidor sanea e descarta o resto. `meetingUrl` só https; `guests` até 10 e-mails (únicos).

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

## Entrada

| Campo | Tipo | Obrigatório | Nota |
|---|---|---|---|
| `contactId` | string (uuid) | sim |  |
| `title` | string | sim |  |
| `kind` | "todo" \| "call" \| "message" \| "meeting" | não |  |
| `dueAt` | string (date-time) | não |  |
| `assigneeId` | string (uuid) | não |  |
| `conversationId` | string (uuid) | não |  |
| `opportunityId` | string (uuid) | não |  |
| `durationMinutes` | integer | não |  |
| `allDay` | boolean | não |  |
| `notes` | string | não |  |
| `meetingUrl` | string | não |  |
| `guests` | string (email)[] | não |  |

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

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "contactId": {
      "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)$"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200
    },
    "kind": {
      "type": "string",
      "enum": [
        "todo",
        "call",
        "message",
        "meeting"
      ]
    },
    "dueAt": {
      "type": "string",
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
    },
    "assigneeId": {
      "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)$"
    },
    "conversationId": {
      "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)$"
    },
    "opportunityId": {
      "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)$"
    },
    "durationMinutes": {
      "type": "integer",
      "minimum": 5,
      "maximum": 1440
    },
    "allDay": {
      "type": "boolean"
    },
    "notes": {
      "type": "string",
      "maxLength": 40000
    },
    "meetingUrl": {
      "type": "string",
      "maxLength": 500,
      "pattern": "^https:\\/\\/\\S+$"
    },
    "guests": {
      "maxItems": 10,
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 254,
        "format": "email",
        "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
      }
    }
  },
  "required": [
    "contactId",
    "title"
  ]
}
```

</details>

## Exemplo

```bash
curl -X POST https://app.atomiks.com.br/api/v1/crm.task_create \
  -H "Authorization: Bearer $ATOMIKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"contactId":"00000000-0000-0000-0000-000000000000","title":"Ligar para fechar","kind":"call"}'
```

CLI:

```bash
node cli/atomiks.mjs crm.task_create --json '{"contactId":"00000000-0000-0000-0000-000000000000","title":"Ligar para fechar","kind":"call"}'
```

MCP: ferramenta `crm_task_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": {
    "task": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "title": {
          "type": "string"
        },
        "kind": {
          "type": "string",
          "enum": [
            "todo",
            "call",
            "message",
            "meeting"
          ]
        },
        "dueAt": {
          "type": [
            "string",
            "null"
          ]
        },
        "done": {
          "type": "boolean"
        },
        "doneAt": {
          "type": [
            "string",
            "null"
          ]
        },
        "contact": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "name": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          "required": [
            "id",
            "name"
          ],
          "additionalProperties": false
        },
        "conversationId": {
          "type": [
            "string",
            "null"
          ]
        },
        "opportunityId": {
          "type": [
            "string",
            "null"
          ]
        },
        "assignee": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "id",
                "name"
              ],
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ]
        },
        "bucket": {
          "type": "string",
          "enum": [
            "overdue",
            "today",
            "upcoming",
            "no_date",
            "done"
          ]
        },
        "durationMinutes": {
          "type": [
            "number",
            "null"
          ]
        },
        "allDay": {
          "type": "boolean"
        },
        "notes": {
          "type": [
            "string",
            "null"
          ]
        },
        "meetingUrl": {
          "type": [
            "string",
            "null"
          ]
        },
        "guests": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "id",
        "title",
        "kind",
        "dueAt",
        "done",
        "doneAt",
        "contact",
        "conversationId",
        "opportunityId",
        "assignee",
        "bucket",
        "durationMinutes",
        "allDay",
        "notes",
        "meetingUrl",
        "guests"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "task"
  ],
  "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).
