Update Files via API

Base URL: <https://app.nanonets.com>

Update fields in a file via API

Overview

This API allows you to update existing fields or add new fields to a file in your Nanonets model. The API uses the PATCH method and requires data from the GET API response to construct the request payload.

Prerequisites

Before using this API, you need to:

  • Obtain your API key from your Nanonets dashboard
  • Get the model ID for your OCR model
  • Retrieve the current field data using the GET API

Endpoint

PATCH /api/v2/Inferences/Model/{model_id}/ImageLevelInference?use_ui_version=true

Parameters

ParameterTypeRequiredDescription
model_idstringYesYour Nanonets model ID
use_ui_versionbooleanYesSet to true to use UI version

Authentication

Include your API key in the request header:

Authorization: Basic base64<api_key:"">

Request Body

The request body should contain the moderated_boxes array with field data. Each field object includes:

Field Object Structure

PropertyTypeDescription
idstringUnique identifier for the field
labelstringField label/name
xmin, ymin, xmax, ymaxnumberBounding box coordinates
scorenumberConfidence score (0-1)
ocr_textstringExtracted text value
statusstringField status (e.g., "moderated")
typestringField type (e.g., "field")
validation_statusstringValidation status (e.g., "success")
pagenumberPage number (0-indexed)
label_idstringLabel identifier
lookup_editedbooleanWhether lookup was edited
lookup_parent_box_idsarray/nullParent box IDs if applicable

How It Works

  1. Get Current Data: First, call the GET API to retrieve existing field data
  2. Modify Data: Update the moderated_boxes array with your changes:
    • Add new fields: Include new field objects with is_new: true
    • Update existing fields: Modify the ocr_text or other properties
    • Delete fields: Remove field objects from the array
  3. Send PATCH Request: Submit the modified data back to this endpoint

Sample Request

curl --location --request PATCH 'https://app.nanonets.com/api/v2/Inferences/Model/d058f6dd-0666-4646-8b48-65669771e5b9/ImageLevelInference?use_ui_version=true' \
--header 'accept: */*' \
--header 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \
--header 'content-type: text/plain;charset=UTF-8' \
--header 'Authorization: Basic base64<api_key:””>' \
--data '{
    "moderated_boxes": [
        {
            "id": "7efa8322-2b23-4a0e-bb83-a0e007eae98d",
            "label": "DOCUMENT_TYPE",
            "xmin": 1278,
            "ymin": 92,
            "xmax": 1568,
            "ymax": 123,
            "score": 0.9999983,
            "ocr_text": "SEA WAYBILL",
            "status": "moderated",
            "type": "field",
            "validation_status": "success",
            "page": 0,
            "label_id": "f21c1578-ebfd-489c-852b-5522dbbf7648",
            "lookup_edited": false,
            "lookup_parent_box_ids": null
        },
        {
            "id": "8af07f53-5c46-4637-8575-68c61c5b2e34",
            "label": "MASTER_BILL_OF_LADING",
            "xmin": 1908,
            "ymin": 93,
            "xmax": 2246,
            "ymax": 124,
            "score": 0.99999666,
            "ocr_text": "MEDUGC750650",
            "status": "moderated",
            "type": "field",
            "validation_status": "success",
            "page": 0,
            "label_id": "285ed018-8f07-4411-8c63-3023653f6f7e",
            "lookup_edited": false,
            "lookup_parent_box_ids": null
        },
        {
            "id": "31314ced-4b23-40ff-9c82-fc29869b6b5d",
            "label": "SHIPPER",
            "xmin": 104,
            "ymin": 328,
            "xmax": 538,
            "ymax": 353,
            "score": 0.9999995,
            "ocr_text": "Exportadora Maria del Transito Ltda .",
            "status": "moderated",
            "type": "field",
            "validation_status": "success",
            "page": 0,
            "label_id": "979b09a1-c996-43e2-b8d8-66696c0263e6",
            "lookup_edited": false,
            "lookup_parent_box_ids": null
        },
        {
            "id": "80901930-2f3f-4837-b106-d5e38533cfb7",
            "label": "CONSIGNEE",
            "xmin": 104,
            "ymin": 539,
            "xmax": 330,
            "ymax": 556,
            "score": 1,
            "ocr_text": "Four Star Sales Inc",
            "status": "moderated",
            "type": "field",
            "validation_status": "success",
            "page": 0,
            "label_id": "272fee89-fa30-4365-b9d6-c5b0fa45d441",
            "lookup_edited": false,
            "lookup_parent_box_ids": null
        },
        {
            "id": "c3a90577-92ca-4e89-809e-db052dd4f0b7",
            "label": "CONSIGNEE_ADDRESS",
            "xmin": 102,
            "ymin": 571,
            "xmax": 383,
            "ymax": 627,
            "score": 1,
            "ocr_text": "2800 Road 136 , Delano ,\nCA93215 , USA",
            "status": "moderated",
            "type": "field",
            "validation_status": "success",
            "page": 0,
            "label_id": "e1d3f04e-e746-4497-bedd-a32aad8d33fa",
            "lookup_edited": false,
            "lookup_parent_box_ids": null
        },
        {
            "id": "d2b91802-97e4-4390-b86a-2d550d21f10f",
            "label": "VESSEL",
            "xmin": 105,
            "ymin": 1039,
            "xmax": 358,
            "ymax": 1060,
            "score": 1,
            "ocr_text": "MSC CASSANDRE",
            "status": "moderated",
            "type": "field",
            "validation_status": "success",
            "page": 0,
            "label_id": "6aa40ecd-e796-4775-8b24-2a7f1dbb3bc7",
            "lookup_edited": false,
            "lookup_parent_box_ids": null
        },
        {
            "id": "bf2da787-738e-40f9-8b33-308d48a7924c",
            "label": "VOYAGE_NUMBER",
            "xmin": 386,
            "ymin": 1039,
            "xmax": 497,
            "ymax": 1060,
            "score": 0.99974793,
            "ocr_text": "NX505R",
            "status": "moderated",
            "type": "field",
            "validation_status": "success",
            "page": 0,
            "label_id": "5cb5cc92-bcbe-46a0-a2de-52f1e1c38283",
            "lookup_edited": false,
            "lookup_parent_box_ids": null
        },
        {
            "id": "c3f0323a-1c2f-4cf4-b2da-963faa7719c3",
            "label": "LOADING_PORT",
            "xmin": 901,
            "ymin": 1032,
            "xmax": 1046,
            "ymax": 1061,
            "score": 0.9999722,
            "ocr_text": "Valparaiso",
            "status": "moderated",
            "type": "field",
            "validation_status": "success",
            "page": 0,
            "label_id": "de82adde-6ddd-4b93-aa1c-012ea6c2f1c4",
            "lookup_edited": false,
            "lookup_parent_box_ids": null
        },
        {
            "id": "0344063c-53a6-47ca-8aaa-2ea57540efc3",
            "label": "LOADING_PORT",
            "xmin": 1063,
            "ymin": 1031,
            "xmax": 1136,
            "ymax": 1058,
            "score": 0.8883551,
            "ocr_text": "Chile",
            "status": "moderated",
            "type": "field",
            "validation_status": "success",
            "page": 0,
            "label_id": "de82adde-6ddd-4b93-aa1c-012ea6c2f1c4",
            "lookup_edited": false,
            "lookup_parent_box_ids": null
        },
        {
            "id": "0e500154-b1e0-447e-9031-220b8f371754",
            "label": "BOOKING",
            "xmin": 108,
            "ymin": 1153,
            "xmax": 315,
            "ymax": 1174,
            "score": 0.99952626,
            "ocr_text": "070ISA1166384",
            "status": "moderated",
            "type": "field",
            "validation_status": "success",
            "page": 0,
            "label_id": "3379978d-fab2-40da-8344-61049383f44a",
            "lookup_edited": false,
            "lookup_parent_box_ids": null
        },
        {
            "id": "f267e320-fe04-4fbb-87d1-7bf538f7e8d6",
            "label": "DISCHARGE_PORT",
            "xmin": 906,
            "ymin": 1129,
            "xmax": 1075,
            "ymax": 1153,
            "score": 0.99999833,
            "ocr_text": "Los Angeles",
            "status": "moderated",
            "type": "field",
            "validation_status": "success",
            "page": 0,
            "label_id": "049a11d0-7317-42e3-82a9-51ffada9400e",
            "lookup_edited": false,
            "lookup_parent_box_ids": null
        },
        {
            "id": "8557594e-ecc0-4033-b562-2da843ca7a6a",
            "label": "COD",
            "xmin": 1093,
            "ymin": 1129,
            "xmax": 1277,
            "ymax": 1153,
            "score": 0.9999999,
            "ocr_text": "United States",
            "status": "moderated",
            "type": "field",
            "validation_status": "success",
            "page": 0,
            "label_id": "6401a9ea-f7e7-4e12-8d90-b4415cdbe22f",
            "lookup_edited": false,
            "lookup_parent_box_ids": null
        },
        {
            "id": "322e1cf7-7b36-4e9e-9eba-61b43615e059",
            "label": "CONTAINER",
            "xmin": 97,
            "ymin": 1457,
            "xmax": 291,
            "ymax": 1478,
            "score": 0.9999913,
            "ocr_text": "CRXU6955280",
            "status": "moderated",
            "type": "field",
            "validation_status": "success",
            "page": 0,
            "label_id": "add1a724-5338-471f-bf6e-b9dbe66b27b8",
            "lookup_edited": false,
            "lookup_parent_box_ids": null
        },
        {
            "id": "148349c1-eca9-49e2-a8b9-87ac762c98a9",
            "label": "TOTAL_CASES",
            "xmin": 595,
            "ymin": 1456,
            "xmax": 650,
            "ymax": 1477,
            "score": 0.9999995,
            "ocr_text": "1876",
            "status": "moderated",
            "type": "field",
            "validation_status": "success",
            "page": 0,
            "label_id": "1bddb825-b638-4e03-9032-9716fb601aea",
            "lookup_edited": false,
            "lookup_parent_box_ids": null
        },
        {
            "id": "c2145de6-afb2-45ad-ade2-1b56af60db16",
            "label": "COMMODITY",
            "xmin": 666,
            "ymin": 1526,
            "xmax": 864,
            "ymax": 1544,
            "score": 0.99583274,
            "ocr_text": "FRESH GRAPES",
            "status": "moderated",
            "type": "field",
            "validation_status": "success",
            "page": 0,
            "label_id": "77009182-1ac0-444c-8b93-2fa0f77da72a",
            "lookup_edited": false,
            "lookup_parent_box_ids": null
        },
        {
            "page": 0,
            "id": "50911cc0-1bc5-11f0-b424-8b0b116d4e05",
            "type": "field",
            "label": "ZACK_CUSTOM",
            "ocr_text": "test2",
            "label_id": "7e852e68-ed22-4910-af30-ac019851686e",
            "is_new": true,
            "xmin": 1098,
            "ymin": 1863,
            "xmax": 1513,
            "ymax": 1990,
            "top": 1863,
            "left": 1098,
            "width": 415,
            "height": 127
        }
    ],
    "page": 0,
    "day_since_epoch": 20168,
    "hour_of_day": 15,
    "id": "75ff0d9d-066b-11f0-b31d-62e85b8f4aab",
    "is_moderated": true
}'

Request Headers

HeaderValueRequired
accept*/*Yes
accept-languageen-GB,en-US;q=0.9,en;q=0.8No
content-typetext/plain;charset=UTF-8Yes
AuthorizationBasic base64<api_key:"">Yes

Common Use Cases

Add New Field

Include a new field object with is_new: true and provide coordinates and text value.

Update Existing Field

Modify the ocr_text property of an existing field to change its extracted value.

Delete Field

Remove the field object from the moderated_boxes array.

Bulk Updates

Update multiple fields in a single API call by including all modified fields in the array.

Important Notes

Key Considerations
  • Always use the GET API response as the base for your PATCH request
  • Ensure all required field properties are included when adding new fields
  • The moderated_boxes array should contain all fields you want to keep
  • Coordinate values should match the document's pixel dimensions
  • New fields require the is_new: true property

Next Steps

After successfully updating fields, you can:

  • Verify changes using the GET API
  • Export the updated data