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

# Create Review Task

> Create review tasks via REST API

<Tip>
  This document introduces how to create review tasks via REST API. Creating a review task requires specifying a rule repository and a list of extraction task IDs. The system will automatically match rules in the rule repository with extraction tasks and execute review for matched rules.
</Tip>

A review task is one execution of applying a rule repository to extraction tasks. After creating a review task, the system will automatically execute the review and generate review results.

## Create Review Task

Submit a review task to review specified extraction tasks:

<CodeGroup>
  ```bash curl icon=terminal wrap theme={null}
  # Using extract_task_ids
  curl -X POST \
    -H "Content-Type: application/json" \
    -H "x-ti-app-id: <your-app-id>" \
    -H "x-ti-secret-code: <your-secret-code>" \
    -d '{
      "workspace_id": "<your-workspace-id>",
      "name": "Review Task 1",
      "repo_id": "31415926",
      "extract_task_ids": ["1234567890", "1234567891"]
    }' \
    "https://docflow.textin.com/api/app-api/sip/platform/v2/review/task/submit"

  # Using batch_number
  # curl -X POST \
  #   -H "Content-Type: application/json" \
  #   -H "x-ti-app-id: <your-app-id>" \
  #   -H "x-ti-secret-code: <your-secret-code>" \
  #   -d '{
  #     "workspace_id": "<your-workspace-id>",
  #     "name": "Review Task 1",
  #     "repo_id": "31415926",
  #     "batch_number": "202412190001"
  #   }' \
  #   "https://docflow.textin.com/api/app-api/sip/platform/v2/review/task/submit"
  ```

  ```python Python expandable icon=python lines theme={null}
  import requests

  ti_app_id = "<your-app-id>"
  ti_secret_code = "<your-secret-code>"
  workspace_id = "<your-workspace-id>"

  host = "https://docflow.textin.com"
  url = "/api/app-api/sip/platform/v2/review/task/submit"

  # Method 1: Using extract_task_ids
  payload = {
      "workspace_id": workspace_id,
      "name": "Review Task 1",
      "repo_id": "31415926",
      "extract_task_ids": ["1234567890", "1234567891"]
  }

  # Method 2: Using batch_number
  # payload = {
  #     "workspace_id": workspace_id,
  #     "name": "Review Task 1",
  #     "repo_id": "31415926",
  #     "batch_number": "202412190001"
  # }

  # Method 3: Using both batch_number and extract_task_ids (system will automatically merge with deduplication)
  # payload = {
  #     "workspace_id": workspace_id,
  #     "name": "Review Task 1",
  #     "repo_id": "31415926",
  #     "batch_number": "202412190001",
  #     "extract_task_ids": ["1234567890", "1234567891"]
  # }

  resp = requests.post(
      url=f"{host}{url}",
      json=payload,
      headers={
          "x-ti-app-id": ti_app_id,
          "x-ti-secret-code": ti_secret_code,
      },
      timeout=60,
  )

  result = resp.json()
  if result.get("code") == 200:
      task_id = result.get("result", {}).get("task_id")
      print(f"Review task created successfully, ID: {task_id}")
  else:
      print(f"Creation failed: {result.get('msg')}")
  ```
</CodeGroup>

**Request Parameters:**

* `workspace_id` (required): Workspace ID
* `name` (required): Task name, max length 100
* `repo_id` (required): Review rule repository ID
* `extract_task_ids` (optional): Array of extraction task IDs, list of extraction task IDs that need to be reviewed
* `batch_number` (optional): Batch number. The system will retrieve all tasks under this batch and merge them with `extract_task_ids` (with deduplication)

**Response Example:**

```json theme={null}
{
  "code": 200,
  "msg": "success",
  "result": {
    "task_id": "31415926"
  }
}
```

## Parameter Description

### Rule Repository ID (repo\_id)

The rule repository ID is the identifier of the review rule repository you created. The system will use all rules in this repository to review extraction tasks.

**Getting Rule Repository ID:**

* Returned when creating a rule repository via the [Create Rule Repository](./rule_management#create-rule-repository) interface
* Obtained by viewing the rule repository list in the interface

### Extraction Task ID (extract\_task\_ids)

Extraction task ID is the identifier of a task that has completed document extraction. Only tasks that have completed extraction can be used as review objects.

**Important Notes:**

* If a parent task ID is provided (e.g., a parent task generated by file split or multi-image crop), the system will automatically retrieve all child tasks of that parent task as input
* If both `batch_number` and `extract_task_ids` are provided, the system will merge all tasks from the batch with `extract_task_ids` (with automatic deduplication)

**Getting Extraction Task ID:**

* From the `task_id` returned by the file upload interface
* From the file query interface (`/api/app-api/sip/platform/v2/file/fetch`) to get file information, where `task_id` is the extraction task ID

### Batch Number (batch\_number)

Batch number is used to specify tasks for review in batches. When `batch_number` is provided, the system will retrieve all tasks under that batch for review.

**Use Cases:**

* Batch review of all files uploaded in the same batch
* Combined with `extract_task_ids` for more flexible task selection

**Example: Get Extraction Task ID**

```python Python icon=python expandable theme={null}
import requests

ti_app_id = "<your-app-id>"
ti_secret_code = "<your-secret-code>"
workspace_id = "<your-workspace-id>"
batch_number = "<your-batch-number>"

host = "https://docflow.textin.com"
url = "/api/app-api/sip/platform/v2/file/fetch"

resp = requests.get(
    url=f"{host}{url}",
    params={
        "workspace_id": workspace_id,
        "batch_number": batch_number
    },
    headers={
        "x-ti-app-id": ti_app_id,
        "x-ti-secret-code": ti_secret_code,
    },
    timeout=60,
)

result = resp.json()
if result.get("code") == 200:
    files = result.get("result", {}).get("files", [])
    extract_task_ids = []
    for file in files:
        # Ensure file has completed extraction (recognition_status == 1)
        if file.get("recognition_status") == 1:
            task_id = file.get("task_id")
            if task_id:
                extract_task_ids.append(task_id)
    
    print(f"Available extraction task IDs: {extract_task_ids}")
```

## Review Task Execution Flow

After creating a review task, the system will execute the review according to the following flow:

1. **Rule Matching**: The system matches rules in the rule repository with extraction task categories
   * Check if the rule's `category_ids` contain the extraction task's categories
   * Check if the extraction task contains fields referenced by the rule

2. **Field Association**: For matched rules, the system retrieves field values referenced by the rule from extraction results

3. **AI Review**: Based on rule prompts and field values, AI makes review judgments

4. **Result Generation**: Generate review results, including review status, reasoning, position anchors, and other information

## Complete Example

Complete review task creation flow:

```python Python icon=python expandable theme={null}
import requests
import time

ti_app_id = "<your-app-id>"
ti_secret_code = "<your-secret-code>"
workspace_id = "<your-workspace-id>"
host = "https://docflow.textin.com"

# 1. Get extraction task IDs
fetch_url = "/api/app-api/sip/platform/v2/file/fetch"
fetch_resp = requests.get(
    url=f"{host}{fetch_url}",
    params={
        "workspace_id": workspace_id,
        "batch_number": "<your-batch-number>"
    },
    headers={
        "x-ti-app-id": ti_app_id,
        "x-ti-secret-code": ti_secret_code,
    },
    timeout=60,
)

fetch_result = fetch_resp.json()
if fetch_result.get("code") != 200:
    print(f"Failed to get file list: {fetch_result.get('msg')}")
    exit(1)

files = fetch_result.get("result", {}).get("files", [])
extract_task_ids = []
for file in files:
    if file.get("recognition_status") == 1:  # Ensure extraction is completed
        task_id = file.get("task_id")
        if task_id:
            extract_task_ids.append(task_id)

if not extract_task_ids:
    print("No available extraction tasks")
    exit(1)

print(f"Found {len(extract_task_ids)} extraction tasks: {extract_task_ids}")

# 2. Create review task
submit_url = "/api/app-api/sip/platform/v2/review/task/submit"
submit_payload = {
    "workspace_id": workspace_id,
    "name": f"Review Task_{int(time.time())}",
    "repo_id": "31415926",  # Rule repository ID
    "extract_task_ids": extract_task_ids
}

submit_resp = requests.post(
    url=f"{host}{submit_url}",
    json=submit_payload,
    headers={
        "x-ti-app-id": ti_app_id,
        "x-ti-secret-code": ti_secret_code,
    },
    timeout=60,
)

submit_result = submit_resp.json()
if submit_result.get("code") == 200:
    task_id = submit_result.get("result", {}).get("task_id")
    print(f"Review task created successfully, Task ID: {task_id}")
    print("Please use the task ID to query review results")
else:
    print(f"Failed to create review task: {submit_result.get('msg')}")
```

## Delete Review Task

If you need to delete a review task:

<CodeGroup>
  ```bash curl icon=terminal wrap theme={null}
  curl -X POST \
    -H "Content-Type: application/json" \
    -H "x-ti-app-id: <your-app-id>" \
    -H "x-ti-secret-code: <your-secret-code>" \
    -d '{
      "workspace_id": "<your-workspace-id>",
      "task_ids": ["31415926", "31415927"]
    }' \
    "https://docflow.textin.com/api/app-api/sip/platform/v2/review/task/delete"
  ```

  ```python Python expandable icon=python lines theme={null}
  import requests

  ti_app_id = "<your-app-id>"
  ti_secret_code = "<your-secret-code>"
  workspace_id = "<your-workspace-id>"

  host = "https://docflow.textin.com"
  url = "/api/app-api/sip/platform/v2/review/task/delete"

  payload = {
      "workspace_id": workspace_id,
      "task_ids": ["31415926", "31415927"]
  }

  resp = requests.post(
      url=f"{host}{url}",
      json=payload,
      headers={
          "x-ti-app-id": ti_app_id,
          "x-ti-secret-code": ti_secret_code,
      },
      timeout=60,
  )

  result = resp.json()
  print(result)
  ```
</CodeGroup>

**Request Parameters:**

* `workspace_id` (required): Workspace ID
* `task_ids` (required): Array of review task IDs

## Notes

1. **Extraction Task Status**: Only tasks that have completed extraction (`recognition_status == 1`) can be used as review objects
2. **Parent Task Handling**: If a parent task ID is provided (e.g., a parent task generated by file split or multi-image crop), the system will automatically retrieve all child tasks of that parent task as input for review
3. **Batch Number and Task ID Combination**: If both `batch_number` and `extract_task_ids` are provided, the system will merge all tasks from the batch with `extract_task_ids` (with automatic deduplication)
4. **Rule Matching**: The system will match rules based on the rule's `category_ids` and the extraction task's categories. Only matched rules will execute review
5. **Field Association**: Ensure that fields referenced by rules exist in extraction results, otherwise it may affect review accuracy
6. **Asynchronous Execution**: Review tasks are executed asynchronously. After creating a task, you need to query review status and results via the [Get Review Results](./get_result) interface

## Related Pages

* [Review Concepts](./quickstart) - Learn about core concepts of the review feature
* [Rule Repository Management](./rule_management) - Learn how to manage review rule repositories
* [Get Review Results](./get_result) - Learn how to get and use review results
