Skip to content

Background

In this example we will see how to finalize an item by adding a new value e.g: If you want to add a completely missing value to an item via finalize api.

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 Get all fields in the workflow.

We can add/correct values for the fields present in the workflow. To check which fields are present in our workflow, we can make following API call:

GET /fields

Body Parameters

item_id ItemID of an item (required)
workflow_id ID of workflow the item is present in (required)

Expected Response

[
  {
    "id": "1ab9e682-09d4-4eea-a559-e374cb4c2564",
    "created_at": "2021-06-22 06:03:14.654376",
    "updated_at": "2021-06-22 06:03:14.654384",
    "display_name": "Supplier name",
    "required": true,
    "visible": true,
    "workflow_id": "d9d9ea26-4728-4dd3-bab2-62495d4c072c",
    "name": "Supplier Name",
    "field_type_id": "be5bdd98-115c-448f-8b92-b2cd76b95f52",
    "shared": true,
    "field_group_id": "d56ce6d1-0ddd-427c-9cba-28bd0e2af1a4"
  },
  {
    "id": "769e979d-608a-4dbc-afea-38e7ca217f55",
    "created_at": "2021-06-22 06:03:14.654403",
    "updated_at": "2021-06-22 06:03:14.654408",
    "display_name": "IBAN",
    "required": false,
    "visible": true,
    "workflow_id": "d9d9ea26-4728-4dd3-bab2-62495d4c072c",
    "name": "IBAN",
    "field_type_id": "c8c227a2-253a-44fd-9225-2ff794ba6c86",
    "shared": true,
    "field_group_id": "d56ce6d1-0ddd-427c-9cba-28bd0e2af1a4"
  },
  {
    "id": "4bcc3ea1-6d81-4057-abd7-2d1f36532d6b",
    "created_at": "2021-06-22 06:03:14.654483",
    "updated_at": "2021-06-22 06:03:14.654488",
    "display_name": "VAT",
    "required": true,
    "visible": true,
    "workflow_id": "d9d9ea26-4728-4dd3-bab2-62495d4c072c",
    "name": "VAT",
    "field_type_id": "e4d259db-cf8a-4f3a-9e64-ca7992e79659",
    "shared": true,
    "field_group_id": "d56ce6d1-0ddd-427c-9cba-28bd0e2af1a4"
  }
]

This response will contain all available fields in the workflow. We can update/add values only to these fields via finalize. Note down the field_id of the value to update.

4.3 Add a missing value

If a value is not interpreted by Aiida, and we want to add it via finalize API, copy the field_id of such value from response of step 4.2

e.g: If we wanted to add IBAN value, but IBAN is not present item values(see response of step 4.1) then copy the field_id of IBAN from response(see response of step 4.2) and use it in finalize API as follows:

Finalize an item to add a missing value

Finalize is called after the item is uploaded. We can finalize the item as follows

POST ​/items/{id}/finalize

Body

{
 "values": [
    {"field_id": "2ac04bd7-237a-4926-8806-5e1c0db08147", "value": "SE2195000099603447926035"},
    {"field_id": "4bcc3ea1-6d81-4057-abd7-2d1f36532d6b", "value": "5000.00"}
  ],
  "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.

4.3 Verify if finalization api added the value correctly.

To verify if finalization api added 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": "SE2195000099603447926035",
      "field_id": "2ac04bd7-237a-4926-8806-5e1c0db08147",
      "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 IBAN value has been added in the response.