Prerequisites
- Prepare a published standard custom extraction application and its
app_id. Confirm the field names, types, and table columns. - Obtain an API Key with access to the application. Include
X-API-KEYin every request. Rule endpoints useapp_id; legacy application credentials are unnecessary. - Use asynchronous extraction. Synchronous extraction disables collaboration by default, and high-speed custom extraction does not support collaboration.
- Start with a dedicated test application. Use documents that match and do not match the rules to verify review routing and corrections before using the integration for business documents.
tenant_name is laiye; use the address and tenant name for your deployment.
For every request, check the HTTP status and then verify that the JSON response has top-level
code=success. HTTP 200 can still contain a business error. Retain message and tips for error handling. For task details, read only the business fields listed on the endpoint page; avoid logging or forwarding the entire response.Complete a review
1
Create and verify review triggers
Call Create collaboration rule. Each application uses one rule set. Use Update collaboration rule for an existing rule set.Rules are conditions that trigger human review. This example routes a document to review when its invoice number equals
INV-001. This is a sample value: the document used to test a match must contain the same invoice number. Replace it with your business condition when integrating.rule_logic=1 means OR: any matching condition triggers review. rule_logic=2 means AND: all conditions must match to trigger review. Use only these two values.After saving, call Get collaboration rule and verify that rule_name, rule, and rule_logic match your request. Write conditions that can be evaluated against field values. A successful response alone does not confirm that the intended conditions were saved.2
Create an extraction task and save its IDs
Call Create document extraction task with the same application used for the rules.In the successful response, If
data.task_id identifies the extraction task. data.metadata.collaboration_task_id identifies the collaboration task for retrieval and correction. Save both values.collaboration_task_id is absent, check the application type and collaboration configuration. Do not substitute the extraction task ID.3
Wait for the review decision and retrieve the content
Call Get collaboration task with Use
collaboration_task_id. When task_state=1, wait and query again. Submit corrections only when task_state=2. A task with task_state=3 passed automatically and needs no correction.extraction_result and collaboration_result from the task details to present the review content. Extraction data.status and collaboration task_state have separate meanings: successful extraction does not mean human review is complete.4
Submit the fields to confirm in one request
Call Update collaboration result. Save the following body as For ordinary fields,
correction.json, replacing the task ID, fields, and values. The example application has “Invoice number” and “Items” fields, with “Name” and “Quantity” columns in “Items”.field_values is an array of strings. For tables, table_values contains rows, each row contains cells, and each cell’s field_values is an array of objects containing field_value. Keep these structures distinct.A table is replaced as a whole. Copy the complete table_values from task details and change only the relevant field_values[].field_value. Preserve the required rows, columns, field_key, and existing properties such as references. Do not infer field identifiers from display names. The example has empty references; retain any actual references unchanged to preserve links to locations in the document.5
Verify the saved task and final extraction output
A successful update returns
data.file_status=4. Retrieve the collaboration task again, confirm task_state=4, and check the saved values. Then call Query document extraction task with the original extraction task_id.extraction_result retains the original automatic extraction. collaboration_result contains review content, and output_result contains the merged final result. Consume output_result after confirming automatic approval or completed human review.IDs and states
The following states apply only to collaboration
task_state:
Integration limits and verification
- Rule dimensions: System dimensions such as overall document and document confidence, and fields whose display names differ from their identifiers, currently have matching limitations. Start with ordinary fields whose names and identifiers match, and verify documents that match and do not match the conditions.
- Rule activation: The returned
rule_statusdoes not currently provide a reliable indication of the saved activation state. After enabling or disabling a rule, verify the behavior with a new document. - Result submissions: Match the field names and types in task details. Use only
string,date, ortable. Submit onlyfield_valuesfor ordinary fields and onlytable_valuesfor tables. Never submit both. Unknown fields or omitted values can complete a task without producing the intended result. - Multiple ordinary values: Submitting fewer values may retain old trailing values. Before reducing or clearing such a field, verify the behavior in a test application; a shorter array is not a reliable full replacement.
- Verification after submission: A submission completes the task, so collect all intended corrections first. After either a successful or failed update response, retrieve the task state and saved content before retrying. An error can occur after changes have already been saved.