Skip to main content

Update Parser

Read the introduction to parsers to understand Parsers.

This guide explains how to update various aspects of a parser, 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 parser:

  1. Parser schema (template_schema)
  2. Parser type (template_type)
  3. Webhook URL
  4. Parser configurations (parser_config)
    • Parse email attachments
    • Parse email body
    • Date format
    • OCR config
    • Query config

Example Implementation using Python#

import requestsimport json
template_id = "710a20fc-e280-43eb-9a9f-5436e600c710"url = f"https://api.documentpro.ai/v1/templates/{template_id}"
# Example payload updating multiple aspectspayload = {    "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('Parser updated successfully')    print(json.dumps(response.json(), indent=2))else:    print('Failed to update parser')    print(response.text)

Update Examples#

You can update specific aspects of the parser 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 parser object in the response body:

{    "template_id": "710a20fc-e280-43eb-9a9f-5436e600c710",    "template_title": "Custom Invoice Parser",    "template_type": "Invoice",    "template_category": "other",    "template_schema": {        "fields": [            // ... updated fields ...        ]    },    "email_id": "test_parser_22_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#

  1. You can update multiple aspects of the parser in a single request by including all relevant fields in your payload.
  2. Only include the fields you want to update in your request payload. Any fields not included will remain unchanged.
  3. When updating the template_schema, ensure that your new schema is valid and includes all necessary fields and subfields.
  4. After updating a parser, it's a good practice to retrieve the parser details to confirm your changes were applied correctly.