Retrieve Result

Integrating the functionality to retrieve data extracted from receipts into your application is a critical step in leveraging OCR capabilities for document management and analysis. This section of the guide will walk you through the process of accessing the ReceiptResult object, which contains detailed information extracted from your scanned receipts.

Understanding the ReceiptResult Structure

The ReceiptResult object encapsulates the processed data from your receipts, organized into a structured format for ease of use:

  • ReceiptResponse: The top-level object that includes all other data structures.
  • DocumentMetadata: Contains metadata about the processed document.
  • ExpenseDocument:
    • expenseIndex: A unique identifier for each expense within the document.
    • blocks: Raw OCR data extracted from the receipt.
    • summaryFields: Key information typically found on invoices and receipts, such as vendor name, receipt number, date, and total amount.
    • lineItemGroups: Detailed entries of items purchased, structured in groups if applicable.
      • lineItemGroupIndex: Identifies the order of tables or item groups within the document.
      • lineItems: Specific items that were purchased, as listed on the receipt.

Asynchronous Processing

It's important to remember that the data extraction is an asynchronous process, handled by Amazon Textract. While extraction is typically completed within seconds, it may occasionally extend up to a minute. To avoid premature retrieval attempts that could result in errors or incomplete data:

  • Wait for Processing Completion: Ensure there's adequate delay after submitting a receipt for processing before attempting to retrieve the extracted data.
  • Check for Data Completeness: Make subsequent retrieval attempts if the initial attempt is unsuccessful, allowing more time for processing completion.

By following these steps and considerations, you can seamlessly integrate OCR data retrieval into your application, enabling access to structured and actionable insights derived from physical receipt scans. This functionality not only enhances the user experience by digitizing paper-based processes but also provides a foundation for advanced data analysis and management within your application.

Client Library

To access the processed data for a specific receipt, the TikiClient.receipt method is used. This method fetches the ReceiptResult for the given receiptId, which is assigned upon successful submission of the receipt image(s) for processing.

// Assuming you have stored the receiptId in a variable named 'receiptId'
let receiptData = await TikiClient.receipt(receiptId);
console.log(receiptData);
TikiClient.receipt(receiptId){ receiptData ->
  // use the receiptData
}
TikiClient.receipt(receiptId){ receiptData in
  // use the receiptData
}

REST API

Following the REST API specs, to retrieve the results from the REST API, use a GET request to the endpoint. The receiptId should be the same used in the upload.

curl --request GET \
  --url https://publish.mytiki.com/receipt/<receiptId \
  --header 'Authorization: Bearer ' \
  --header 'Content-Type: application/json'