import requests
import json
def amend_split_category(workspace_id, task_id, split_tasks, app_id, secret_code):
"""
Amend category and page numbers for file split tasks
Args:
workspace_id: Workspace ID
task_id: Parent task ID (file split task ID)
split_tasks: Split task list, format:
[
{
"category": "Category name",
"pages": [0, 1] # Page number array, starting from 0
},
...
]
app_id: Application ID
secret_code: Secret code
"""
url = "https://docflow.textin.com/api/app-api/sip/platform/v2/file/amend_category"
headers = {
"x-ti-app-id": app_id,
"x-ti-secret-code": secret_code,
"Content-Type": "application/json"
}
payload = {
"workspace_id": workspace_id,
"task_id": task_id,
"split_tasks": split_tasks
}
response = requests.post(url, headers=headers, json=payload)
return response.json()
# Usage example
if __name__ == "__main__":
WORKSPACE_ID = "1234567890"
PARENT_TASK_ID = "1234567890" # Parent task ID (task_type = 2)
APP_ID = "<your-app-id>"
SECRET_CODE = "<your-secret-code>"
# Important: Must include all split child file information
# Assuming the original file is split into 3 child files:
# - Child file 1: Pages 1-2, category "Invoice"
# - Child file 2: Pages 3-5, category "Contract"
# - Child file 3: Pages 6-7, category "Receipt"
#
# If you only need to modify child file 1's category, you must also include information for child files 2 and 3
split_tasks = [
{
"category": "Electronic Invoice (Regular)", # Modified category
"pages": [0, 1] # Keep original page numbers
},
{
"category": "Contract", # Keep original category
"pages": [2, 3, 4] # Keep original page numbers
},
{
"category": "Receipt", # Keep original category
"pages": [5, 6] # Keep original page numbers (Note: original file pages 6-7 correspond to page numbers 5-6)
}
]
result = amend_split_category(WORKSPACE_ID, PARENT_TASK_ID, split_tasks, APP_ID, SECRET_CODE)
print(json.dumps(result, indent=2, ensure_ascii=False))