# タスク

Source: https://won.dev/ja/docs/tasks

タスクは、同じエンドポイントへの多数の呼び出しをバックグラウンドで代わりに実行します。エージェントが1件ずつ送ったり、実行中ずっと接続を開いておいたりする必要はありません。

- `enrich.people.email.find`、`enrich.email.verify`、`signals.find` は `inputs` を受け取ります。最大100件で、それぞれが1回の呼び出しのリクエストボディです。`trade.leads.find` は `limit` を最大500にできる1つの `input` を受け取り、タスクがリストを順にページ送りします。
- 各呼び出しは単独の呼び出しとまったく同じように実行・課金されるので、タスクの費用はその呼び出しの費用の合計です。タスクの作成、取得、一覧、キャンセルは無料です。`max_cost` を超えるおそれのあるタスクは拒否され、`dry_run: true` なら最大費用がわかります。
- タスクを作成すると、すぐに `202 Accepted` が返り、`Location` ヘッダーにそのタスクのURLが入ります。`status` が `running` でなくなるまで、そこを `GET /tasks/{id}` で確認してください。
- 残高やキーの予算が尽きたタスクは `failed` で止まり、それまでの結果は残ります。
- タスクが終わると、`task.completed` があなたの[Webhook](/ja/docs/email/webhooks-create)と `GET /events` に届きます。顧客IDなど独自の `metadata` は、タスクとそのイベントにそのまま返ります。
- 結果は終了後7日間保存されます。データ提供元が保存を認めていない場合は1日です。タスク自体は30日間一覧に残ります。
- テストキーでは各呼び出しがサンドボックスで動き、課金されません。また、テストキーで作られたタスクしか見えません。
- 同じことは、[MCPサーバー](/ja/docs/mcp)の `task_create` ツールと `task_get` ツールでもできます。

## タスクを作成 [#create]

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

同じエンドポイントへの多数の呼び出しをバックグラウンドで実行します。`inputs` の項目ごとに1回ずつ、仕事用メールアドレスの検索（`enrich.people.email.find`）、メールアドレスの検証（`enrich.email.verify`）、企業シグナルの確認（`signals.find`）を最大100回、または `limit` を最大500にした1つの `input` から最大500件のリード（`trade.leads.find`）を取得します。各呼び出しは単独で呼び出したときとまったく同じように動き、返った結果に対してエンドポイントの価格で課金されます。同じ呼び出しの繰り返しと、30日以内に支払い済みの結果は無料です。タスクの作成自体は無料です。`max_cost` を超えるおそれのあるタスクは拒否され、`dry_run: true` なら最大費用だけを返します。残高やキーの予算が尽きると、タスクは `failed` で終わり、それまでの結果は残ります。進み具合は `GET /tasks/{id}` で確認するか、`task.completed` イベントを待ってください。結果は終了後7日間保存されます。`Idempotency-Key` ヘッダーをつければ、再試行で2つ目のタスクが作られることはありません。対象のエンドポイント：`trade.leads.find`、`enrich.people.email.find`、`enrich.email.verify`、`signals.find`。

### パラメーター [#create-parameters]

パラメーターはJSONのリクエストボディで渡します。

| パラメーター | 型 | 必須 | 説明（APIの原文） |
| --- | --- | --- | --- |
| `operation` | `trade.leads.find` \| `enrich.people.email.find` \| `enrich.email.verify` \| `signals.find` | はい | What to run: `trade.leads.find`, `enrich.people.email.find`, `enrich.email.verify`, `signals.find`. |
| `inputs` | object[] | いいえ | For a batch: up to 100 parts, each the body of one call of the endpoint, such as `{"email": "jane@example.com"}`. |
| `input` | object | いいえ | 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 | いいえ | The most the whole task may cost, in US dollars. A task that could cost more is refused before anything runs. |
| `dry_run` | boolean | いいえ | Only say the most the task can cost. Nothing is created or charged. Default: `false`. |
| `metadata` | object | いいえ | 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. |

### レスポンス [#create-response]

| フィールド | 型 | 説明（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. |

### 例 [#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
  }
}
```

## タスクを取得 [#get]

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

タスクの進み具合と費用、そして順番どおりの結果を返します。各結果は、そのエンドポイントを呼び出したときのレスポンスと同じで、HTTPステータスがつきます。結果は `cursor` でページ送りできます。`status` が `running` の間は、1分ほどおいてもう一度確認するか、`task.completed` イベントを待ってください。結果は終了から7日後に削除されます（`results_expire_at`）。無料です。

### パラメーター [#get-parameters]

`id` はパスに含めます。それ以外はクエリ文字列で渡します。

| パラメーター | 型 | 必須 | 説明（APIの原文） |
| --- | --- | --- | --- |
| `id` | string | はい | Task ID, such as `task_7p1q8w3e5r4k2m9x`. |
| `limit` | integer | いいえ | How many to return, 1 to 100. Default: `20`. |
| `cursor` | string | いいえ | To get the next page, pass `next_cursor` of the previous response back unchanged, with the same parameters. |

### レスポンス [#get-response]

| フィールド | 型 | 説明（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. |

### 例 [#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
  }
}
```

## タスクの一覧 [#list]

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

タスクを新しい順に、ステータス、進み具合、費用とともに返します。結果は `GET /tasks/{id}` で取得します。無料です。

### パラメーター [#list-parameters]

パラメーターはクエリ文字列で渡します。

| パラメーター | 型 | 必須 | 説明（APIの原文） |
| --- | --- | --- | --- |
| `limit` | integer | いいえ | How many to return, 1 to 100. Default: `25`. |
| `cursor` | string | いいえ | To get the next page, pass `next_cursor` of the previous response back unchanged, with the same parameters. |

### レスポンス [#list-response]

| フィールド | 型 | 説明（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. |

### 例 [#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
  }
}
```

## タスクをキャンセル [#cancel]

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

実行中のタスクを止め、新しい呼び出しを始めないようにします。すでに始まっていた呼び出しは最後まで実行され、通常どおり課金されます。それまでの結果はすべて残ります。`status: canceled` の `task.completed` イベントが送られます。無料です。

### パラメーター [#cancel-parameters]

`id` はパスに含めます。

| パラメーター | 型 | 必須 | 説明（APIの原文） |
| --- | --- | --- | --- |
| `id` | string | はい | Task ID, such as `task_7p1q8w3e5r4k2m9x`. |

### レスポンス [#cancel-response]

| フィールド | 型 | 説明（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. |

### 例 [#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
  }
}
```