Update Workflow
Read the introduction to parsers to understand Parsers.
This guide explains how to update various aspects of a Workflow, including its schema, settings, and configurations.
API Endpoint
PUT https://api.documentpro.ai/v1/templates/{template_id}
What You Can Update
You can update the following aspects of a Workflow:
- Workflow schema (template_schema)
- Workflow type (template_type)
- Webhook URL
- Workflow configurations (parser_config)
- Parse email attachments
- Parse email body
- Date format
- OCR config
- Query config
Example Implementation using Python
import requests
import json
template_id = "710a20fc-e280-43eb-9a9f-5436e600c710"
url = f"https://api.documentpro.ai/v1/templates/{template_id}"
# Example payload updating multiple aspects
payload = {
"template_type": "Invoice",
"template_schema": {
"fields": [
{
"name": "invoice_number",
"type": "text",
"description": "Unique identifier for the invoice"
},
{
"name": "total_amount",
"type": "number",
"description": "Total amount on the invoice"
},
{
"name": "line_items",
"type": "table",
"description": "Invoice line items",
"subFields": [
{
"name": "description",
"type": "text",
"description": "Description of item"
},
{
"name": "quantity",
"type": "number",
"description": "Quantity of item"
},
{
"name": "unit_price",
"type": "number",
"description": "Price per unit"
}
]
}
]
},
"webhook_url": "https://your-webhook-url.com",
"parser_config": {
"date_format": "%d/%m/%y",
"ocr_config": {
"detect_tables": true
},
"query_config": {
"query_model": "gpt-4o-mini"
}
}
}
headers = {
'x-api-key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
}
response = requests.put(url, headers=headers, json=payload)
if response.status_code == 200:
print('Workflow updated successfully')
print(json.dumps(response.json(), indent=2))
else:
print('Failed to update Workflow')
print(response.text)
Update Examples
You can update specific aspects of the Workflow by including only the relevant fields in your payload. Here are some examples:
Update Webhook URL Only
{
"webhook_url": "https://your-webhook-url.com"
}
Update Email Setting Only
{
"parser_config": {
"parse_email_attachments": false,
"parse_email_body": true
}
}
Update Date Format Only
{
"parser_config": {
"date_format": "%d/%m/%y"
}
}
Update OCR Config Only
{
"parser_config": {
"ocr_config": {
"detect_tables": true,
// ... other OCR settings ...
}
}
}
Update Query Config Only
{
"parser_config": {
"query_config": {
"query_model": "gpt-4o-mini",
// ... other query settings ...
}
}
}
Response
Successful Response (Status Code: 200)
A successful update will return a 200 status code and the updated Workflow object in the response body:
{
"template_id": "710a20fc-e280-43eb-9a9f-5436e600c710",
"template_title": "Custom Invoice Workflow",
"template_type": "invoice",
"template_category": "other",
"template_schema": {
"fields": [
// ... updated fields ...
]
},
"email_id": "custom_invoice_workflow_fbb499@inbox.documentpro-ai.com",
"webhook_url": "https://your-webhook-url.com",
"parser_config": {
"parse_email_attachments": false,
"parse_email_body": true,
"date_format": "%d/%m/%y",
"ocr_config": {
"detect_tables": true,
// ... other OCR settings ...
},
"query_config": {
"query_model": "gpt-4o-mini",
// ... other query settings ...
}
},
"created_at": "2023-11-15T12:13:12.056281"
}
Error Response (Status Codes: 400, 404, 500)
For errors, you will receive a response with the following structure:
{
"success": false,
"error": "error_code",
"message": "descriptive error message"
}
Important Notes
- You can update multiple aspects of the Workflow in a single request by including all relevant fields in your payload.
- Only include the fields you want to update in your request payload. Any fields not included will remain unchanged.
- When updating the
template_schema
, ensure that your new schema is valid and includes all necessary fields and subfields. - After updating a Workflow, it's a good practice to retrieve the Workflow details to confirm your changes were applied correctly.