> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Extraction of main invoice fields

> Extract main invoice fields with FlexiCapture for Invoices Cloud by uploading a file, running a capture task, polling the status, and downloading results.

ABBYY FlexiCapture for Invoices Cloud includes a ready-to-use application designed specifically for invoice processing. This application recognizes and extracts all necessary data fields from most documents without any additional adjustments. For a detailed list of fields that are extracted from invoices by default, see the [Captured fields](/flexi-capture/cloud/cloud-f-cfor-invoices-fields) section.

Follow the steps below to process invoices.

<Steps>
  <Step title="Get the authorization header">
    Get the authorization header using the credentials of one of your applications. For details, see the [Authentication](/flexi-capture/cloud/cloud-f-cfor-invoices-api-auth) section. The examples below use the sample header `Basic QWxhZGRpbjpPcGVuU2VzYW1l`.
  </Step>

  <Step title="Upload a file">
    Upload a file in a valid [input format](/flexi-capture/cloud/cloud-f-cfor-invoices-formats) to the server using the [File.Upload](/flexi-capture/cloud/cloud-f-cfor-invoices-api-upload-file) method. In the response, you get the file's identifier and token, which are used in all subsequent requests concerning the file.

    ```bash theme={null}
    curl -X POST \
      --header "Accept: application/json" \
      --header "Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l" \
      --form "file=@/path/to/file/US_1.png" \
      "https://api-eu.flexicapture.com/v2/file"
    ```

    The response contains the uploaded file's metadata:

    ```json theme={null}
    {
      "id": "5eeb762149c6470fdc65a84c",
      "token": "4B5A1A00E7A82C2AF31E20CADE7284DDA43DED30",
      "name": "US_1.png",
      "extension": ".png",
      "hash": "E75133BA4FC50B7197C2842D7A8A8AE615C37E38714C7773B1F8E2904EC62537A199129CD3B737673FBAB1DE63CBD5D428705443ADD2E1BA6223B7DD60070FDA",
      "size": 369090,
      "mime": "image/png",
      "is_recognizable": true,
      "account": "5dae591d3c66a51ae8be9896",
      "application": "5dae591e91375010bcd78362",
      "email": "user@abbyy.com",
      "created": "2020-02-02T14:11:45.5338461Z",
      "expiring": "2020-03-03T14:11:45.5338254Z"
    }
    ```
  </Step>

  <Step title="Start a processing task">
    Start a processing task to begin data extraction using the Task.Run method. You can specify multiple files in this request. The request may contain the following optional parameters: invoice [region](/flexi-capture/cloud/cloud-f-cfor-invoices-languages), verification type, and the [export format](/flexi-capture/cloud/cloud-f-cfor-invoices-formats) for the results. The response contains a task identifier, which you need in the next steps.

    ```bash theme={null}
    curl -X POST \
      --header "Content-Type: application/json" \
      --header "Accept: application/json" \
      --header "Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l" \
      -d '{
        "properties": {
          "region": "US",
          "export_format": "Xls",
          "verification_type": "NoVerification"
        },
        "files": [
          {
            "id": "5eeb762149c6470fdc65a84c",
            "token": "4B5A1A00E7A82C2AF31E20CADE7284DDA43DED30"
          }
        ]
      }' \
      "https://api-eu.flexicapture.com/v2/task/capture/invoices"
    ```

    The response describes the newly created task:

    ```json theme={null}
    {
      "id": "5eeb7bf728613d1e04a70782",
      "number": "1126563",
      "batch_id": 0,
      "type": "ic",
      "is_realtime_enabled": false,
      "processing_priority": "Normal",
      "is_demo": false,
      "properties": {
        "region": "US",
        "export_format": "Xls",
        "verification_type": "NoVerification"
      },
      "account": "5dae591d3c66a51ae8be9896",
      "email": "user@abbyy.com",
      "application": "5dae591e91375010bcd78362",
      "created": "2020-02-02T14:36:39.441Z",
      "progress": 0,
      "status": "Submitted",
      "is_deleted": false,
      "is_billed": false,
      "documents": [
        {
          "files": {
            "source": {
              "id": "5eeb762149c6470fdc65a84c",
              "token": "4B5A1A00E7A82C2AF31E20CADE7284DDA43DED30",
              "name": "US_1.png"
            }
          },
          "data": {},
          "is_moved": false
        }
      ],
      "is_extra_error": false
    }
    ```
  </Step>

  <Step title="Check the task status">
    Processing the task takes some time, so the extracted data is not available immediately. Check the task status using the identifier you received when starting the task, with the [Task.Get](/flexi-capture/cloud/cloud-f-cfor-invoices-api-get-task) method. Wait until the status changes to `Done`.

    ```bash theme={null}
    curl -X GET \
      --header "Accept: application/json" \
      --header "Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l" \
      "https://api-eu.flexicapture.com/v2/task/5eeb7bf728613d1e04a70782"
    ```

    When the task is complete, the response includes the `target` files to download:

    ```json theme={null}
    {
      "id": "5eeb7bf728613d1e04a70782",
      "number": "1126563",
      "batch_id": 2640691,
      "type": "ic",
      "is_realtime_enabled": false,
      "processing_priority": "Normal",
      "is_demo": false,
      "properties": {
        "region": "US",
        "export_format": "Xls",
        "verification_type": "NoVerification"
      },
      "account": "5dae591d3c66a51ae8be9896",
      "email": "user@abbyy.com",
      "application": "5dae591e91375010bcd78362",
      "created": "2020-02-02T14:36:39.441Z",
      "started": "2020-02-02T14:36:50.308Z",
      "billed": "2020-02-02T14:37:14.35Z",
      "delivered": "2020-02-02T14:37:14.328Z",
      "progress": 100,
      "status": "Done",
      "is_deleted": false,
      "is_billed": true,
      "documents_count": 1,
      "pages_count": 1,
      "documents": [
        {
          "files": {
            "source": {
              "id": "5eeb762149c6470fdc65a84c",
              "token": "4B5A1A00E7A82C2AF31E20CADE7284DDA43DED30",
              "name": "US_1.png"
            },
            "target": {
              "id": "5eeb7c1963ee5a1268123b96",
              "token": "A01EFC05BBB787DC6825F08E51B56CF3E066210E",
              "name": "Data_00000001.xls"
            },
            "verification_layer_page_0": {
              "id": "5eeb7c1a63ee5a1268123b97",
              "token": "18921FFB4C944056CB3ED00768F90724ADF0CB69",
              "name": "verification_layer_page_2.xml"
            }
          },
          "data": {
            "region": "us",
            "export_format": "xls",
            "verification_type": "noverification",
            "vendor_id": "1",
            "vendor_name": "AA APPAREL",
            "total": "20208",
            "currency": "USD"
          },
          "is_moved": false
        }
      ],
      "is_extra_error": false
    }
    ```
  </Step>

  <Step title="Download the output files">
    After the status changes to `Done`, download the output files using their identifiers and tokens (the `target` file information in the response from the previous step), with the [File.Download](/flexi-capture/cloud/cloud-f-cfor-invoices-api-download-file) method. Repeat this request for each input file in the task request.

    ```bash theme={null}
    curl -X GET \
      --header "Accept: application/json" \
      --header "Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l" \
      "https://api-eu.flexicapture.com/v2/file/5eeb7c1963ee5a1268123b96/A01EFC05BBB787DC6825F08E51B56CF3E066210E"
    ```

    If successful, the server returns a 200 OK HTTP status and the file contents.
  </Step>

  <Step title="Delete the task">
    After downloading the output data, delete the task to remove all input and output files, using the Task.Delete method with the task identifier.

    ```bash theme={null}
    curl -X DELETE \
      --header "Accept: application/json" \
      --header "Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l" \
      "https://api-eu.flexicapture.com/v2/task/5eeb7bf728613d1e04a70782"
    ```

    If successful, the server returns a `204 No Content` HTTP status.
  </Step>
</Steps>

If the request contains errors, the server returns one of the HTTP response codes to indicate the reason for failure. For details, see the [Request errors](/flexi-capture/cloud/cloud-f-cfor-invoices-api-errors) section.
