# Tarefas

Source: https://won.dev/pt-BR/docs/tasks

Uma tarefa faz por você, em segundo plano, muitas chamadas a um mesmo endpoint, para que um agente não precise enviá-las uma a uma nem manter uma conexão aberta enquanto elas rodam.

- `enrich.people.email.find`, `enrich.email.verify` e `signals.find` recebem `inputs`: até 100 partes, cada uma o corpo de uma chamada. `trade.leads.find` recebe um único `input` cujo `limit` vai até 500, e a tarefa percorre a lista por você.
- Cada parte roda e é cobrada exatamente como uma chamada avulsa, então uma tarefa custa o que as chamadas dela custam. Criar, consultar, listar e cancelar uma tarefa é grátis. `max_cost` recusa uma tarefa que possa custar mais, e `dry_run: true` informa o máximo que ela pode custar.
- Criar uma tarefa responde `202 Accepted` na hora, com a URL da tarefa no cabeçalho `Location`: acompanhe-a ali com `GET /tasks/{id}` até que `status` deixe de ser `running`.
- Uma tarefa que fica sem saldo, ou sem o orçamento da chave, para como `failed` e mantém o que fez.
- Quando uma tarefa termina, `task.completed` vai para os seus [webhooks](/pt-BR/docs/email/webhooks-create) e para `GET /events`. A sua própria `metadata`, como o ID de um cliente, volta na tarefa e nesse evento.
- Os resultados ficam guardados por 7 dias depois do fim, ou 1 dia quando uma fonte não permite guardá-los. A tarefa em si aparece na lista por 30 dias.
- Uma chave de teste roda cada parte no sandbox, nunca gera cobrança e só vê as tarefas criadas com chave de teste.
- O mesmo está nas ferramentas `task_create` e `task_get` do [servidor MCP](/pt-BR/docs/mcp).

## Criar uma tarefa [#create]

`POST https://api.won.dev/v1/tasks`

Executa em segundo plano muitas chamadas a um mesmo endpoint: até 100 buscas de e-mail corporativo (`enrich.people.email.find`), verificações de endereço (`enrich.email.verify`) ou checagens de sinais de empresas (`signals.find`), uma por item de `inputs`, ou até 500 leads (`trade.leads.find`) a partir de um único `input` cujo `limit` vai até 500. Cada parte funciona exatamente como uma chamada avulsa: é cobrada pelo preço do endpoint pelo que retorna, e repetições e resultados pagos nos últimos 30 dias são grátis. Criar a tarefa é grátis. `max_cost` recusa uma tarefa que possa custar mais, e `dry_run: true` informa o máximo que ela pode custar. Uma tarefa que fica sem saldo ou sem orçamento da chave termina como `failed` e mantém o que fez. Acompanhe com `GET /tasks/{id}` ou espere o evento `task.completed`. Os resultados ficam guardados por 7 dias depois do fim. Com um cabeçalho `Idempotency-Key`, uma nova tentativa nunca cria uma segunda tarefa. Endpoints: `trade.leads.find`, `enrich.people.email.find`, `enrich.email.verify`, `signals.find`.

### Parâmetros [#create-parameters]

Os parâmetros vão no corpo JSON.

| Parâmetro | Tipo | Obrigatório | Descrição (texto original da API) |
| --- | --- | --- | --- |
| `operation` | `trade.leads.find` \| `enrich.people.email.find` \| `enrich.email.verify` \| `signals.find` | sim | What to run: `trade.leads.find`, `enrich.people.email.find`, `enrich.email.verify`, `signals.find`. |
| `inputs` | object[] | não | For a batch: up to 100 parts, each the body of one call of the endpoint, such as `{"email": "jane@example.com"}`. |
| `input` | object | não | For `trade.leads.find`: the body of one call, with `limit` up to 500 (default 100). The task goes down the ranked list until it has `limit` leads or the list ends. |
| `max_cost` | number | não | The most the whole task may cost, in US dollars. A task that could cost more is refused before anything runs. |
| `dry_run` | boolean | não | Only say the most the task can cost. Nothing is created or charged. Default: `false`. |
| `metadata` | object | não | Your own keys and values, such as `{"customer_id": "c_812"}`: up to 20 keys of at most 40 characters, each value a string of at most 500. Returned as given, and in the events about it. |

### Resposta [#create-response]

| Campo | Tipo | Descrição (texto original da API) |
| --- | --- | --- |
| `data` | object | The task, and the most it can cost. |
| `data.dry_run` | boolean | True when nothing was created: the answer to `dry_run: true`. |
| `data.max_cost` | number | The most the task can cost, in US dollars. |
| `data.task` | object \| null | The task. Null on a dry run. |
| `data.task.id` | string | Task ID, such as `task_7p1q8w3e5r4k2m9x`. |
| `data.task.operation` | string | The endpoint it runs, such as `enrich.email.verify`. |
| `data.task.status` | `running` \| `completed` \| `failed` \| `canceled` | `running`, then `completed`, `failed` (it stopped early, and `error` says why) or `canceled`. |
| `data.task.progress` | object | How far it got. |
| `data.task.progress.done` | integer | Parts answered, or for leads the leads found. |
| `data.task.progress.total` | integer | Parts of the batch, or the leads asked for. |
| `data.task.progress.failed` | integer | Parts answered with an error. They cost nothing. |
| `data.task.cost` | number | What it cost so far, in US dollars. |
| `data.task.max_cost` | number | The most it can cost, in US dollars. |
| `data.task.error` | object \| null | Why it stopped early: the error of the call that stopped it, such as `insufficient_balance`. Null otherwise. |
| `data.task.error.code` | string |  |
| `data.task.error.message` | string |  |
| `data.task.metadata` | object | Your own keys and values, as you gave them. Empty when none were. |
| `data.task.created_at` | string | When it was created, ISO 8601. |
| `data.task.completed_at` | string \| null | When it ended. Null while it runs. |
| `data.task.results_expire_at` | string \| null | When the results are deleted: 7 days after the end, 1 day when a source does not allow keeping them. Null while it runs. |
| `notice` | string \| null | A plain sentence when there is something to know about this answer. Null otherwise. |
| `usage` | object | Nothing is charged here. The balance, for reference. |
| `usage.cost` | number | What this call cost, in US dollars. |
| `usage.balance` | number | The balance left after this call, in US dollars. |
| `usage.replayed` | boolean | True when this is a repeat of a request from the last 24 hours. Repeats are free. |

### Exemplo [#create-example]

```bash
curl https://api.won.dev/v1/tasks \
  -H "Authorization: Bearer $WON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "operation": "enrich.people.email.find",
  "inputs": [
    {
      "first_name": "Dana",
      "last_name": "Reyes",
      "domain": "harbor-chairs.com"
    },
    {
      "linkedin_url": "https://www.linkedin.com/in/lee-okafor"
    }
  ],
  "max_cost": 3,
  "metadata": {
    "customer_id": "c_812"
  }
}'
```

```json
{
  "data": {
    "dry_run": false,
    "max_cost": 0.06,
    "task": {
      "id": "task_7p1q8w3e5r4k2m9x",
      "operation": "enrich.people.email.find",
      "status": "running",
      "progress": {
        "done": 0,
        "total": 2,
        "failed": 0
      },
      "cost": 0,
      "max_cost": 0.06,
      "error": null,
      "metadata": {
        "customer_id": "c_812"
      },
      "created_at": "2026-11-20T13:40:00.000Z",
      "completed_at": null,
      "results_expire_at": null
    }
  },
  "notice": null,
  "usage": {
    "cost": 0,
    "balance": 48.14,
    "replayed": false
  }
}
```

## Consultar uma tarefa [#get]

`GET https://api.won.dev/v1/tasks/{id}`

Uma tarefa, até onde ela chegou e quanto custou, com os resultados em ordem: cada um é a resposta que uma chamada ao endpoint dá, com o status HTTP. Navegue pelos resultados com `cursor`. Enquanto `status` for `running`, consulte de novo em um minuto ou espere o evento `task.completed`. Os resultados são apagados 7 dias depois do fim (`results_expire_at`). Grátis.

### Parâmetros [#get-parameters]

`id` faz parte do caminho. Os demais vão na query string.

| Parâmetro | Tipo | Obrigatório | Descrição (texto original da API) |
| --- | --- | --- | --- |
| `id` | string | sim | Task ID, such as `task_7p1q8w3e5r4k2m9x`. |
| `limit` | integer | não | How many to return, 1 to 100. Default: `20`. |
| `cursor` | string | não | To get the next page, pass `next_cursor` of the previous response back unchanged, with the same parameters. |

### Resposta [#get-response]

| Campo | Tipo | Descrição (texto original da API) |
| --- | --- | --- |
| `data` | object | The task, and a page of its results. |
| `data.task` | object |  |
| `data.task.id` | string | Task ID, such as `task_7p1q8w3e5r4k2m9x`. |
| `data.task.operation` | string | The endpoint it runs, such as `enrich.email.verify`. |
| `data.task.status` | `running` \| `completed` \| `failed` \| `canceled` | `running`, then `completed`, `failed` (it stopped early, and `error` says why) or `canceled`. |
| `data.task.progress` | object | How far it got. |
| `data.task.progress.done` | integer | Parts answered, or for leads the leads found. |
| `data.task.progress.total` | integer | Parts of the batch, or the leads asked for. |
| `data.task.progress.failed` | integer | Parts answered with an error. They cost nothing. |
| `data.task.cost` | number | What it cost so far, in US dollars. |
| `data.task.max_cost` | number | The most it can cost, in US dollars. |
| `data.task.error` | object \| null | Why it stopped early: the error of the call that stopped it, such as `insufficient_balance`. Null otherwise. |
| `data.task.error.code` | string |  |
| `data.task.error.message` | string |  |
| `data.task.metadata` | object | Your own keys and values, as you gave them. Empty when none were. |
| `data.task.created_at` | string | When it was created, ISO 8601. |
| `data.task.completed_at` | string \| null | When it ended. Null while it runs. |
| `data.task.results_expire_at` | string \| null | When the results are deleted: 7 days after the end, 1 day when a source does not allow keeping them. Null while it runs. |
| `data.results` | object[] | The results of this page, in order. |
| `data.results[].index` | integer | The part of `inputs` it answers, or the page of leads, from 0. |
| `data.results[].status` | integer | The HTTP status of the call: 200, or the status of its error. |
| `data.results[].body` | object | The answer, exactly as a call of the endpoint returns it: its body or its error. |
| `has_more` | boolean | Whether more results follow this page. |
| `next_cursor` | string \| null | Pass it as `cursor` to get the next page of results. Null on the last page. |
| `notice` | string \| null | A plain sentence when there is something to know about this answer. Null otherwise. |
| `usage` | object | Nothing is charged here. The balance, for reference. |
| `usage.cost` | number | What this call cost, in US dollars. |
| `usage.balance` | number | The balance left after this call, in US dollars. |
| `usage.replayed` | boolean | True when this is a repeat of a request from the last 24 hours. Repeats are free. |

### Exemplo [#get-example]

```bash
curl "https://api.won.dev/v1/tasks/task_7p1q8w3e5r4k2m9x?limit=1" \
  -H "Authorization: Bearer $WON_API_KEY"
```

```json
{
  "data": {
    "task": {
      "id": "task_7p1q8w3e5r4k2m9x",
      "operation": "enrich.people.email.find",
      "status": "completed",
      "progress": {
        "done": 100,
        "total": 100,
        "failed": 2
      },
      "cost": 1.86,
      "max_cost": 3,
      "error": null,
      "metadata": {
        "customer_id": "c_812"
      },
      "created_at": "2026-11-20T13:40:00.000Z",
      "completed_at": "2026-11-20T13:46:12.000Z",
      "results_expire_at": "2026-11-27T13:46:12.000Z"
    },
    "results": [
      {
        "index": 0,
        "status": 200,
        "body": {
          "data": {
            "email": {
              "address": "dana.reyes@harbor-chairs.com",
              "status": "verified"
            },
            "person": null
          },
          "query": {
            "first_name": "Dana",
            "last_name": "Reyes",
            "domain": "harbor-chairs.com"
          },
          "notice": null,
          "usage": {
            "unit": "person_email",
            "records": 1,
            "already_paid": 0,
            "cost": 0.03,
            "balance": 49.97,
            "replayed": false
          }
        }
      }
    ]
  },
  "has_more": true,
  "next_cursor": "cur_Zx81kQp4b2JtMW0uMXJ6ZzQ",
  "notice": null,
  "usage": {
    "cost": 0,
    "balance": 48.14,
    "replayed": false
  }
}
```

## Listar tarefas [#list]

`GET https://api.won.dev/v1/tasks`

As suas tarefas, da mais recente para a mais antiga, com status, progresso e custo. Os resultados vêm com `GET /tasks/{id}`. Grátis.

### Parâmetros [#list-parameters]

Os parâmetros vão na query string.

| Parâmetro | Tipo | Obrigatório | Descrição (texto original da API) |
| --- | --- | --- | --- |
| `limit` | integer | não | How many to return, 1 to 100. Default: `25`. |
| `cursor` | string | não | To get the next page, pass `next_cursor` of the previous response back unchanged, with the same parameters. |

### Resposta [#list-response]

| Campo | Tipo | Descrição (texto original da API) |
| --- | --- | --- |
| `data` | object[] | The tasks, newest first. |
| `data[].id` | string | Task ID, such as `task_7p1q8w3e5r4k2m9x`. |
| `data[].operation` | string | The endpoint it runs, such as `enrich.email.verify`. |
| `data[].status` | `running` \| `completed` \| `failed` \| `canceled` | `running`, then `completed`, `failed` (it stopped early, and `error` says why) or `canceled`. |
| `data[].progress` | object | How far it got. |
| `data[].progress.done` | integer | Parts answered, or for leads the leads found. |
| `data[].progress.total` | integer | Parts of the batch, or the leads asked for. |
| `data[].progress.failed` | integer | Parts answered with an error. They cost nothing. |
| `data[].cost` | number | What it cost so far, in US dollars. |
| `data[].max_cost` | number | The most it can cost, in US dollars. |
| `data[].error` | object \| null | Why it stopped early: the error of the call that stopped it, such as `insufficient_balance`. Null otherwise. |
| `data[].error.code` | string |  |
| `data[].error.message` | string |  |
| `data[].metadata` | object | Your own keys and values, as you gave them. Empty when none were. |
| `data[].created_at` | string | When it was created, ISO 8601. |
| `data[].completed_at` | string \| null | When it ended. Null while it runs. |
| `data[].results_expire_at` | string \| null | When the results are deleted: 7 days after the end, 1 day when a source does not allow keeping them. Null while it runs. |
| `has_more` | boolean | Whether more follow this page. |
| `next_cursor` | string \| null | Pass it as `cursor` to get the next page. Null on the last page. |
| `notice` | string \| null | A plain sentence when there is something to know about this answer. Null otherwise. |
| `usage` | object | Nothing is charged here. The balance, for reference. |
| `usage.cost` | number | What this call cost, in US dollars. |
| `usage.balance` | number | The balance left after this call, in US dollars. |
| `usage.replayed` | boolean | True when this is a repeat of a request from the last 24 hours. Repeats are free. |

### Exemplo [#list-example]

```bash
curl "https://api.won.dev/v1/tasks?limit=1" \
  -H "Authorization: Bearer $WON_API_KEY"
```

```json
{
  "data": [
    {
      "id": "task_7p1q8w3e5r4k2m9x",
      "operation": "enrich.people.email.find",
      "status": "completed",
      "progress": {
        "done": 100,
        "total": 100,
        "failed": 2
      },
      "cost": 1.86,
      "max_cost": 3,
      "error": null,
      "metadata": {
        "customer_id": "c_812"
      },
      "created_at": "2026-11-20T13:40:00.000Z",
      "completed_at": "2026-11-20T13:46:12.000Z",
      "results_expire_at": "2026-11-27T13:46:12.000Z"
    }
  ],
  "has_more": false,
  "next_cursor": null,
  "notice": null,
  "usage": {
    "cost": 0,
    "balance": 48.14,
    "replayed": false
  }
}
```

## Cancelar uma tarefa [#cancel]

`POST https://api.won.dev/v1/tasks/{id}/cancel`

Interrompe uma tarefa em andamento: nenhuma parte nova começa. As partes que já estavam em andamento terminam e são cobradas normalmente, e tudo o que ela fez fica guardado. Envia `task.completed` com `status: canceled`. Grátis.

### Parâmetros [#cancel-parameters]

`id` faz parte do caminho.

| Parâmetro | Tipo | Obrigatório | Descrição (texto original da API) |
| --- | --- | --- | --- |
| `id` | string | sim | Task ID, such as `task_7p1q8w3e5r4k2m9x`. |

### Resposta [#cancel-response]

| Campo | Tipo | Descrição (texto original da API) |
| --- | --- | --- |
| `data` | object | The task, canceled. |
| `data.id` | string | Task ID, such as `task_7p1q8w3e5r4k2m9x`. |
| `data.operation` | string | The endpoint it runs, such as `enrich.email.verify`. |
| `data.status` | `running` \| `completed` \| `failed` \| `canceled` | `running`, then `completed`, `failed` (it stopped early, and `error` says why) or `canceled`. |
| `data.progress` | object | How far it got. |
| `data.progress.done` | integer | Parts answered, or for leads the leads found. |
| `data.progress.total` | integer | Parts of the batch, or the leads asked for. |
| `data.progress.failed` | integer | Parts answered with an error. They cost nothing. |
| `data.cost` | number | What it cost so far, in US dollars. |
| `data.max_cost` | number | The most it can cost, in US dollars. |
| `data.error` | object \| null | Why it stopped early: the error of the call that stopped it, such as `insufficient_balance`. Null otherwise. |
| `data.error.code` | string |  |
| `data.error.message` | string |  |
| `data.metadata` | object | Your own keys and values, as you gave them. Empty when none were. |
| `data.created_at` | string | When it was created, ISO 8601. |
| `data.completed_at` | string \| null | When it ended. Null while it runs. |
| `data.results_expire_at` | string \| null | When the results are deleted: 7 days after the end, 1 day when a source does not allow keeping them. Null while it runs. |
| `notice` | string \| null | A plain sentence when there is something to know about this answer. Null otherwise. |
| `usage` | object | Nothing is charged here. The balance, for reference. |
| `usage.cost` | number | What this call cost, in US dollars. |
| `usage.balance` | number | The balance left after this call, in US dollars. |
| `usage.replayed` | boolean | True when this is a repeat of a request from the last 24 hours. Repeats are free. |

### Exemplo [#cancel-example]

```bash
curl https://api.won.dev/v1/tasks/task_7p1q8w3e5r4k2m9x/cancel \
  -H "Authorization: Bearer $WON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'
```

```json
{
  "data": {
    "id": "task_7p1q8w3e5r4k2m9x",
    "operation": "enrich.people.email.find",
    "status": "canceled",
    "progress": {
      "done": 35,
      "total": 100,
      "failed": 0
    },
    "cost": 0.84,
    "max_cost": 3,
    "error": null,
    "metadata": {
      "customer_id": "c_812"
    },
    "created_at": "2026-11-20T13:40:00.000Z",
    "completed_at": "2026-11-20T13:46:12.000Z",
    "results_expire_at": "2026-11-27T13:46:12.000Z"
  },
  "notice": null,
  "usage": {
    "cost": 0,
    "balance": 48.14,
    "replayed": false
  }
}
```