Skip to content

Background

In this example we will see how to finalize an item by correcting an existing value. e.g: If we want to correct a value reported by Aiida during finalization, we can follow these steps

4.1 Get the Item ID

Before finalizing we will do a GET on items to check extracted values of the item, and check the values section in the reponse

GET /items/{id}

Expected Response

{
  "id": "2f34a75a-def6-11eb-b96c-aa44bcbf3f2f",
  "created_at": "2021-07-07 07:37:30.025329",
  "updated_at": "2021-07-07 07:37:35.318702",
  "name": "Andeverywhere",
  "error": null,
  "values": [
    {
      "id": "31ebd798-def6-11eb-a23a-2231628dbe6d",
      "value": "4950.00",
      "extracted": null,
      "count": 1,
      "page_number": 0,
      "location": [
        {
          "x": 0.45795523290986084,
          "y": 0.7058572039333049
        },
        {
          "x": 0.45795523290986084,
          "y": 0.7905087644292432
        },
        {
          "x": 0.5771324863883848,
          "y": 0.7058572039333049
        },
        {
          "x": 0.5771324863883848,
          "y": 0.7905087644292432
        }
      ],
      "field_id": "4bcc3ea1-6d81-4057-abd7-2d1f36532d6b",
      "valid": true,
      "column_index": null,
      "algorithm": "q",
      "confidence": 1,
      "field_name": "VAT"
    },
    {
      "id": "31ebda78-def6-11eb-9715-2231628dbe6d",
      "value": "Andeverywhere",
      "extracted": null,
      "count": 1,
      "page_number": 0,
      "location": [
        {
          "x": 0.45795523290986084,
          "y": 0.7058572039333049
        },
        {
          "x": 0.45795523290986084,
          "y": 0.7905087644292432
        },
        {
          "x": 0.5771324863883848,
          "y": 0.7058572039333049
        },
        {
          "x": 0.5771324863883848,
          "y": 0.7905087644292432
        }
      ],
      "field_id": "1ab9e682-09d4-4eea-a559-e374cb4c2564",
      "valid": true,
      "column_index": null,
      "algorithm": "q",
      "confidence": 1,
      "field_name": "Supplier Name"
    }
  ],
  "state": "interpreted",
  "document_type": null,
  "user_id": null,
  "column_id": "48eb909c-9e75-4eda-a34e-88b37d507e35",
  "collection_id": "0975d00e-e577-4c9a-8c75-21d95eaca556",
  "original_file_id": "2f369fc4-def6-11eb-b96c-aa44bcbf3f2f",
  "locked_by_user_id": null,
  "page_count": 1,
  "comment_count": 0,
  "status_messages": []
}

4.2 Correct a existing value

Now if we want to correct an existing value (e.g VAT in the above example response), we need to pass the field_id and corrected value in the finalize endpoint.

Finalize an item to correct existing value

Finalize is called after the item is uploaded. We can finalize the item by a call to

POST ​/items/{id}/finalize

Body

{
 "values": [
    {"field_id": "4bcc3ea1-6d81-4057-abd7-2d1f36532d6b", "value": "5000.00"},
    {"field_id: "1ab9e682-09d4-4eea-a559-e374cb4c2564", "value": "Andeverywhere"}
  ],
  "classification": "SUPPLIER_INVOICE"
}

Body parameters

Parameter Comment
values List of field values (json, optional)
classification Classification of item (string, optional). Must match one of the classifications of your workflows. Skip if not applicable.

Schema for values

field_name Field name (must match an existing field) (optional)
field_id Field id (must match an existing field) (optional)
value The correct value

One of either field_name or field_id must be present.

4.3 Verify if finalization api updated the value correctly.

To verify if finalization api updated the value correctly, please perform a GET call on item_id

GET /items/{id}

Expected Response

{
  "id": "2f34a75a-def6-11eb-b96c-aa44bcbf3f2f",
  "created_at": "2021-07-07 07:37:30.025329",
  "updated_at": "2021-07-07 07:37:35.318702",
  "name": "Andeverywhere",
  "error": null,
  "values": [
    {
      "id": "31ebd798-def6-11eb-a23a-2231628dbe6d",
      "value": "5000.00",
      "field_id": "4bcc3ea1-6d81-4057-abd7-2d1f36532d6b",
      "valid": true
    },
    {
      "id": "31ebda78-def6-11eb-9715-2231628dbe6d",
      "value": "Andeverywhere",
      "extracted": null,
      "count": 1,
      "page_number": 0,
      "location": [
        {
          "x": 0.45795523290986084,
          "y": 0.7058572039333049
        },
        {
          "x": 0.45795523290986084,
          "y": 0.7905087644292432
        },
        {
          "x": 0.5771324863883848,
          "y": 0.7058572039333049
        },
        {
          "x": 0.5771324863883848,
          "y": 0.7905087644292432
        }
      ],
      "field_id": "1ab9e682-09d4-4eea-a559-e374cb4c2564",
      "valid": true,
      "column_index": null,
      "algorithm": "q",
      "confidence": 1,
      "field_name": "Supplier Name"
    }
  ],
  "state": "interpreted",
  "document_type": null,
  "user_id": null,
  "column_id": "48eb909c-9e75-4eda-a34e-88b37d507e35",
  "collection_id": "0975d00e-e577-4c9a-8c75-21d95eaca556",
  "original_file_id": "2f369fc4-def6-11eb-b96c-aa44bcbf3f2f",
  "locked_by_user_id": null,
  "page_count": 1,
  "comment_count": 0,
  "status_messages": []
}

NOTE: In the response we will see that the VAT value has been updated to 5000.00 after our finalize API call.