Uploading Receipts

Integrate OCR capabilities for scanning and processing receipts directly within your app across Android, iOS, and Capacitor platforms.

Client Library

Integrating the OCR functionality into your application is straightforward with our Client Library, which provides a seamless method for scanning physical receipts using the mobile device's camera and digital receipts through e-mail scraping. This section of the guide focuses on utilizing the TikiClient.scan method for capturing receipt images, the TikiClient.scrape method to download receipts from e-mail and the TikiClient.publish method for processing those files.

Scanning Receipts

The TikiClient.scan method is designed to simplify the process of capturing receipt images. Depending on your platform, the method behaves slightly differently:

  • Android: Triggers a callback with a Bitmap? containing the captured image. If the user cancels, the Bitmap? will be null.
  • iOS: Initiates a callback with a UIImage? containing the captured image data. If canceled, the UIImage? will be nil.
  • Capacitor: Returns a Promise resolving to the base64 string of the image/jpg. If canceled, the Promise resolves to undefined.
TikiClient.scan { image ->
    // Use image here
}
TikiClient.scan { image in
    // Use image here               
}
const image = await TikiClient.scan();
// Use image here

Receipt Scraping

The TikiClient.scrape method simplifies the extraction of receipt data from linked email accounts. It enables scraping and downloading of receipts, which can then be processed through OCR on mytiki.com. The process automatically resumes if interrupted.

Utilize the TikiClient.scrape method to initiate scraping, with an onAttachment callback for accessing attachment data. No attachment data is retained after the callback is called.

The attachment data is composed by 2 fields:

  • type: the mime type of the attachment
  • data: the binary data

You can use the type field to identify if the file is an image or PDF to call the appropriate method to upload to mytiki.com.

Example usage:

TikiClient.scrape { attachment ->
    // Utilize the attachment data
    // e.g., TikiClient.publish(attachment.data)
}
TikiClient.scrape { attachment in
    // Utilize the attachment data
    // e.g., TikiClient.publish(attachment.data)
}

Uploading Receipts

After capturing the receipt image(s) or email attachments, use the TikiClient.publish method to upload them for processing. This method can handle both single and multiple images or PDFs, accommodating even lengthy receipts by accepting an array of images.

val image: Bitmap // Single image
await TikiClient.publish(image)

val pdf: File // Single attachment
await TikiClient.publish(pdf)
let image: UIImage // Single image
await TikiClient.publish(image)

let pdf: Data // Single attachment
await TikiClient.publish(pdf)
let image: string = "base64ImageString" // Base64 string for a single image
await TikiClient.publish([image])

const pdf: File // a single PDF file
await TikiClient.publish([pdf]);

Uploading Long Receipts

For receipts that extend beyond a single image, simply compile the images into a list or array and pass them to the TikiClient.publish method. Our system processes each image individually and combines the extracted data seamlessly.

val images: Array<Bitmap> // Multiple images
val receiptId = await TikiClient.publish(images)
let images: [UIImage] // Multiple images
let receiptId = await TikiClient.publish(images)
let images: string[] // Array of base64 strings for multiple images
let receiptId = await TikiClient.publish(images)

Once a receipt is uploaded and processed, you're provided with a unique ID for each receipt. This ID is crucial for accessing the processed data later on through our API.

REST API

To upload a a receipt image through the REST API, do a POST request to the https://publish.mytiki.com/receipt/<receiptId> endpoint.

The receiptId parameter is used to send multiple images of the same receipt, to handle lengthy receipts, and to retrieve the result. It must be a unique ID for each address, otherwise different receipts will be treated as the same, reducing the quality of your data.

The image or PDF should be sent as binary data in the body of the request.

curl --request POST \
  --url https://publish.mytiki.com/receipt/<receiptId> \
  --header 'Authorization: Bearer <ADDRESS TOKEN>' \
  --header 'Content-Type: <image/jpeg or image/png or application/pdf>' \
  --data <binary-data>