> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cleariflow.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 非同期ジョブ

> `jobs` エンドポイントはスクレイピングタスクをキューに入れ、ステータスと結果をポーリングできます — 高ボリュームや遅いページに最適です。

## はじめに

### ベース URL

```
https://scrape.cleariflow.com/v1/jobs
```

## ジョブの作成

同期エンドポイントと同じ `ScrapeRequest` ペイロードで非同期スクレイピングジョブをキューに追加します。

### リクエスト例

```bash theme={"system"}
curl -X POST 'https://scrape.cleariflow.com/v1/jobs' \
  -H 'Content-Type: application/json' \
  -d '{
    "request": {
      "api_key": "YOUR_UNIQUE_API_KEY",
      "url": "https://example.com"
    },
    "priority": 10
  }'
```

成功したリクエストはジョブ ID を返します：

<ResponseExample>
  ```json theme={"system"}
  {
    "job_id": "550e8400-e29b-41d4-a716-446655440000"
  }
  ```
</ResponseExample>

### ジョブ作成パラメータ

<ParamField body="request" type="Object" required>
  同期スクレイピングエンドポイントと同じフィールド（`url`、`render`、`actions`、`cookies` など）を持つ `ScrapeRequest` オブジェクト。
</ParamField>

<ParamField body="priority" type="Integer">
  ジョブ優先度。値が大きいほど先に処理されます。デフォルト: 0。
</ParamField>

## ジョブステータスの取得

ID でジョブをポーリングし、ステータスを確認し、完了後に結果を取得します。

### ベース URL

```
https://scrape.cleariflow.com/v1/jobs/{job_id}
```

### リクエスト例

```bash theme={"system"}
curl 'https://scrape.cleariflow.com/v1/jobs/550e8400-e29b-41d4-a716-446655440000'
```

ジョブ実行中：

<ResponseExample>
  ```json theme={"system"}
  {
    "job_id": "550e8400-e29b-41d4-a716-446655440000",
    "status": "running"
  }
  ```
</ResponseExample>

正常完了時：

<ResponseExample>
  ```json theme={"system"}
  {
    "job_id": "550e8400-e29b-41d4-a716-446655440000",
    "status": "done",
    "result": {
      "ok": true,
      "html": "<!DOCTYPE html><html>...</html>",
      "meta": {
        "elapsed_ms": 8123
      }
    }
  }
  ```
</ResponseExample>

### ジョブステータス値

| ステータス     | 説明                           |
| --------- | ---------------------------- |
| `queued`  | ジョブがキューで待機中。                 |
| `running` | ブラウザセッションがアクティブ。             |
| `done`    | スクレイピング完了。`result` に出力が含まれる。 |
| `failed`  | スクレイピング失敗。`error` に説明が含まれる。  |

### レスポンスパラメータ

<ResponseField name="job_id" type="String">
  非同期ジョブの一意の識別子。
</ResponseField>

<ResponseField name="status" type="String">
  現在のジョブステータス: `queued`、`running`、`done`、`failed`。
</ResponseField>

<ResponseField name="result" type="Object">
  スクレイピング結果オブジェクト（同期エンドポイントレスポンスと同じ構造）。`status` が `done` の場合に返されます。
</ResponseField>

<ResponseField name="error" type="String">
  エラーメッセージ。`status` が `failed` の場合に返されます。
</ResponseField>

<ResponseField name="meta" type="Object">
  ジョブ実行に関する追加メタデータ。
</ResponseField>
