By Cath Kirkland, 18 July 2023
Are you tired of spending countless hours manually entering data from documents?
Check out OCR for a little slice of magic! OCR (Optical Character Recognition) is a fantastic technology that can transform printed or hand-written text into JSON format that can then be easily used to populate FileMaker records.
In this example we will use the paid web service by Veryfi to read invoice documents but there are many other OCR services available. Our choice to use Veryfi was mostly based on the standard JSON reponse they return.
Are you ready to get started? Let's dive in! Download the example file below:
First, you will need to create an account with Veryfi.
You have 14 days to use this account for free with limitations. After this point you will need to create a paid account, or add billing details to your own.
Next, go to the Settings → Keys page and create a new API key
The information you will need to record from this page includes the following:
and the URL https://api.veryfi.com/api/v7/partner/documents/
Now you have all the tools you need, create a layout and add a container field for receiving the document you want to read.
The file contents will need to be Base64 encoded to include into the cURL which we will build up and send to Veryfi.
Now we have the contents of the file all nicely packaged up into a variable. Veryfi requires two pieces of information to be sent. The file name and the encoded file. Build up your data string like so escaping the quotes as needed.
\"file_name\": \"" & GetContainerAttribute ( HOME::fileadd_dragdrop ; "filename" )& "\"" &
", \"file_data\": \"application/pdf;base64, " & $file & "\"" &
End result required:
Veryfi supports the following file types .pdf, .htm, .jpeg, .avif, .heic, .gif, .webp, .txt, .html, .heif, .ofd, .png, .jpg, .zip with a maximum file size of 20mb.
Next we want to build up the CURL request. In this case we are using a POST and sending the authorization details of our API key and account set up earlier.
"-X POST" & ¶ &"-H \"Accept: application/json\"" & ¶ &
"-H \"Content-Type: application/json\"" & ¶ &
"-H \"CLIENT-ID: " & $clientid & "\"" & ¶ &
"-H \"AUTHORIZATION: apikey " & $account & ":" & $apikey & "\"" & ¶ &
"--dump-header $responsestatus " & ¶ & //gets us a response code
"-d @$Data" & ¶ &
"--trace $$trace “ [Optional; used for troubleshooting]
Now use Insert from URL to send the request
In this case we are setting the response into the $Response variable so you can check this for a valid response of 201.
The document will be returned as JSON listing out elements such as but not limited to:
Check out Veryfi's documentation for further information on the JSON response or other details.
As mentioned, we always include an example file with our articles to help you learn and explore. We spend a lot of time on these so please do check it out.