Create or Update Template

This REST API provides the functionality to save or update files that can be used in Parse endpoint. It’s easy to define and save the template to extract data from invoices, prices or other kinds of your typical documents. The table below contains the full list of properties.

NameDescriptionComment
TemplatePathThe path of the template, located in the storage.Required.
FileInfo.StorageNameStorage nameIt could be omitted for default storage.
TemplateUser-generated template to extract metadata from the document.Required.

Template

NameDescriptionComment
Template.FieldsTemplate fields.Required if Template. Tables are not provided.
Field.FieldNameA unique template field name.Required.
Field.PageIndexThe page index.An integer value that represents the index of the page where the template item is located; null if the template item is located on any page.
FieldPosition. FieldPositionTypeProvides a template field position.Possible values are: “Fixed”, “Linked”, “Regex”. Required.
FieldPosition.RectangleA rectangular area on the page that bounds the field value.Required if “Fixed” FieldPositionType is set.
FieldPosition.RegexString expression to find a field value by a regular expression.Required if “Regex” FieldPositionType is set.
FieldPosition.MatchCaseThe value that indicates whether a test case isn’t ignored.It is used if the Regex parameter is set.
FieldPosition.LinkedFieldNameThe name of the linked field.Required if “Linked” FieldPositionType is set.
FieldPosition.IsLeftLinkedThe value that indicates whether a field is searched by the left from the linked field.It is used if “Linked” FieldPositionType is set.
FieldPosition.IsRightLinkedThe value that indicates whether a field is searched by the right from the linked field.It is used if “Linked” FieldPositionType is set.
FieldPosition.IsTopLinkedThe value that indicates whether a field is searched by the top from the linked field.It is used if “Linked” FieldPositionType is set.
FieldPosition.IsBottomLinkedThe value that indicates whether a field is searched by the bottom from the linked field.It is used if “Linked” FieldPositionType is set.
FieldPosition.SearchAreaThe size of the area where a field is searched.Required if “Linked” FieldPositionType is set.
SearchArea.HeightThe height of the search area.
SearchArea.WidthThe width of the search area.
FieldPosition.AutoScaleThe value that indicates whether SearchArea is scaled by the linked field size.It is used if “Linked” FieldPositionType is set.
Template.TablesTemplate tables.Required if Template. Fields are not provided.
Table.FieldNameA unique template table name.Required.
Table.PageIndexThe page index.An integer value that represents the index of the page where the template item is located; null if the template item is located on any page.
Table.DetectorParametesIt provides parameters for the table detection algorithms.Required if TableLayout is not provided.
DetectorParameters.MinRowCountThe minimum number of table rows.
DetectorParameters.MinColumnCountThe minimum number of table columns.
DetectorParameters.MinVerticalSpaceThe minimum space between the table columns.
DetectorParameters.HasMergedCellsThe value that indicates whether the table has merged cells.
DetectorParameters.RectangleThe rectangular area that contains the table.
DetectorParameters.VerticalSeparatorsThe table columns separators.
Table.TableLayoutProvides the template table layout which is used Table to define table position.Required if DetectorParameters is not provided.
TableLayout.VerticalSeparatorsThe table columns separators.
TableLayout.HorizontalSeparatorsThe table rows separators.

Rectangle

NameDescriptionComment
Rectangle.PositionThe coordinates of the upper-left corner of the rectangular area.Required if Rectangle. Coordinates are not provided.
Position.XX-coordinate of upper-left rectangle corner.
Position.YY-coordinate of upper-left rectangle corner.
Rectangle.SizeRepresents the size of rectangular area.Required if Rectangle. Coordinates are not provided.
Size.HeightThe height of the rectangular area.
Size.WidthThe width of the rectangular area.
Rectangle.CoordinatesCoordinates of the rectangular area edges.
Coordinates.TopThe y-coordinate of the top edge of the rectangular area.
Coordinates.RightThe x-coordinate of the right edge of the rectangular area.
Coordinates.LeftThe x-coordinate of the left edge of the rectangular area.
Coordinates.BottomThe y-coordinate of the bottom edge of the rectangular area.

Resource URI

HTTP PUT ~/template

Swagger UI lets you call this REST API directly from the browser.

cURL example

The following example demonstrates how to Create or Update Template.

# First get JSON Web Token
# Please get your Client Id and Client Secret from https://dashboard.groupdocs.cloud/applications.
# Kindly place Client Id in "client_id" and Client Secret in "client_secret" argument.
curl -v "https://api.groupdocs.cloud/connect/token" \
-X POST \
-d "grant_type#client_credentials&client_id#xxxx&client_secret#xxxx" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
  
# cURL example to join several documents into one
curl -v "https://api.groupdocs.cloud/v1.0/parser/template" \
-X PUT \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: Bearer 
<jwt token>" \
-d "{
    "Template": {
        "Fields": [
            {
                "FieldName": "Address",
                "FieldPosition": {
                    "FieldPositionType": "Fixed",
                    "Rectangle": {
                        "Position": {
                            "X": 13.0,
                            "Y": 35.0
                        },
                        "Size": {
                            "Height": 10.0,
                            "Width": 100.0
                        }
                    },
                    "MatchCase": false,
                    "IsLeftLinked": false,
                    "IsRightLinked": false,
                    "IsTopLinked": false,
                    "IsBottomLinked": false,
                    "AutoScale": false
                }
            },
            {
                "FieldName": "Company",
                "FieldPosition": {
                    "FieldPositionType": "Linked",
                    "MatchCase": false,
                    "LinkedFieldName": "Address",
                    "IsLeftLinked": false,
                    "IsRightLinked": false,
                    "IsTopLinked": false,
                    "IsBottomLinked": true,
                    "SearchArea": {
                        "Height": 15.0,
                        "Width": 100.0
                    },
                    "AutoScale": true
                }
            }
        ],
        "Tables": [
            {
                "TableName": "Totals",
                "DetectorParameters": {
                    "Rectangle": {
                        "Position": {
                            "X": 300.0,
                            "Y": 385.0
                        },
                        "Size": {
                            "Height": 220.0,
                            "Width": 65.0
                        }
                    }
                }
            }
        ]
    },
    "TemplatePath": "templates/template_2.json"
}"

Response will contain storage path and url to resultant template file

{
    "url": "https://api.groupdocs.cloud/v1.0/parser/storage/file/templates/template_2.json",
    "templatePath": "templates/template_2.json"
}

SDK examples

Using an SDK (API client) is the quickest way for a developer to speed up the development. An SDK takes care of a lot of low-level details of making requests and handling responses and lets you focus on writing code specific to your particular project. Check out our GitHub repository for a complete list of GroupDocs.Parser Cloud SDKs along with working examples, to get you started in no time. Please check Available SDKs article to learn how to add an SDK to your project.