Skip to main content

Update the schema

Read the introduction to parsers to understand Parsers.

You can update the schema of a parser using the API. This is useful when you want to add or remove fields from a parser.

Guide to updating a parser schema#

API Endpoint#

PUT https://api.documentpro.ai/v1/templates/{template_id}

Example Implementation using Python#

import requestsimport json
url = "https://api.documentpro.ai/v1/templates/710a20fc-e280-43eb-9a9f-5436e600c710"
payload = json.dumps({  "template_type": "Invoice",  "template_schema": {    "fields": [      {        "name": "buyer_name",        "type": "text",        "description": "name of the buyer"      },      {        "name": "total_amount",        "type": "number"      },      {        "name": "line_items",        "type": "table",        "description": "invoice line items",        "subFields": [          {            "name": "description",            "type": "text",            "description": "description of item"          },          {            "name": "subtotal",            "type": "number"          }        ]      }    ]  }})
headers = {  'x-api-key': 'YOUR_API_KEY',  'Content-Type': 'application/json'}
response = requests.request("PUT", url, headers=headers, data=payload)
# If the request was successful, status_code will be 200if response.status_code == 200:    print('Parser updated successfully')else:    print('Failed to update parser')

You can include either template_type or template_schema or both in the request body.

Response body#

A 200 status code will have the following body structure.

{    "template_id": "710a20fc-e280-43eb-9a9f-5436e600c710",    "template_title": "Custom Invoice Parser",    "template_type": "Invoice",    "template_category": "other",    "template_schema": {      "fields": [        {          "name": "buyer_name",          "type": "text",          "description": "name of the buyer"        },        {          "name": "total_amount",          "type": "number"        },        {          "name": "line_items",          "type": "table",          "description": "invoice line items",          "subFields": [            {              "name": "description",              "type": "text",              "description": "description of item"            },            {              "name": "subtotal",              "type": "number"            }          ]        }      ]    }    "email_id": "test_parser_22_fbb499@inbox.documentpro-ai.com",    "webhook_url": null,    "parser_config": {...},    "created_at": "2023-11-15T12:13:12.056281"}

For status codes 400, 404 and 500 you will get the following response body.

{    "success": false,    "error": "error message",    "message": "descriptive error message"}