Receipt image parser

FREEMIUM
By Astor AI | Updated 22 дня назад | Business
Health Check

N/A

README

Photo/Image analysis and feedback API.

Quick and dirty guide:

  1. 📷📄 Grab a jpeg image file (or a PDF file) and store it in myimage.jpg (mypdf.pdf)
  2. ⚙️ Run curl -F file=@myimage.jpg https://api.astor.ai/v1/send-photo-mime
  3. 🎉 Profit!

Detailed use-cases

There are many use-cases for this API, but a main use-case is implementing
analysis of receipts in mobile applications.

For the use-cases explained below, we will assume a number of variables. Some of these are optional, but the accuracy of the results improve by setting these.

Variables identifying the image/PDF sent to the API:

  • $this_1_uuid, $this_2_uuid are identifiers for images/PDFs sent to the API
  • $file_1 $file_2 are the files containing the images/PDFs.

The user who is taking the picture (optional):

A reference to the models that will be used:

  • $config_uuid. You will get this identifier from support and you will use the same identifier in all invocations.

Information about the company we are doing accounting for:

Example variables are shown on the right ➡

# Example variables:
this_1_uuid=029a6a30-4605-4fe9-8971-8389d510a5c1
this_2_uuid=1c92f760-8373-43e5-a411-3d843188dbb0
user_uuid=7920dafb-5eaa-4df1-a403-e8fea1287065
file_1=/path/to/file1.jpg
file_2=/path/to/file2.jpg
config_uuid=38a41e2f-8743-4e8a-85fc-70267de1c693
org_number=556939-1377
company_name=Formal Privacy AB
tax_number=SE556939137701

Step 1: The user with id $user_uuid takes a picture, which is stored as $file_1. The app generates an UUID representing this picture, namely $this_1_uuid.
The user (it could be an accountant or an end user) is doing accounting for the company $company_name, which has the registered company number $org_number, and tax identification number $tax_number.
The image is sent to the API like this ➡

# Step 1, sending an image to the API
curl -X POST \
  'https://api.astor.ai/v1/send-photo-mime?this=${this_1_uuid}' \
                                          '&user=${user_uuid}' \
                                          '&config=${config_uuid}' \
                                          '&orgNumber=${org_number}' \
                                          '&companyName=${company_name}' \
                                          '&taxNumber=${tax_number}' \
  -H 'Content-Type: image/jpeg' \
  -H 'Authorization: Bearer ey...' \
  -H 'Accept: application/json' \
  -F file=${file_1}

The results of the analysis comes back as a SendPhotoResponse
entity.

Now two things can happen:

  1. The result is fine. Everything is 😂 and our users 😍 the app.
  2. The result does not contain enough information. In this case the user might need to take another photo.

Case 1

The user is happy. The user accepts the data. In this case you should invoke
the /v1/tag-receipt endpoint with the information the user accepted.

Case 2

The user is not happy. Let us capture another image. This image,
$file_2 with $this_2_uuid is sent to the API like this ➡

# Case 2, resend another image
last_result=....
curl -X POST \
  'https://api.astor.ai/v1/send-photo-mime?this=${this_2_uuid}' \
                                          '&lastfile=${this_1_uuid}' \
                                          '&user=${user_uuid}' \
                                          '&lastResult=${last_result}' \
                                          '&config=${config_uuid}' \
                                          '&orgNumber=${org_number}' \
                                          '&companyName=${company_name}' \
                                          '&taxNumber=${tax_number}' \
  -H 'Content-Type: image/jpeg' \
  -H 'Authorization: Bearer ey...' \
  -H 'Accept: application/json' \
  -F file=${file_2}

What this does is send a reference to the previous file that belongs to the
same receipt
. This reference is sent in two ways: through the lastfile
parameter as well as through the lastResult parameter.

Feedback API

In order to learn and update the model, the /v1/tag-receipt endpoint is used.
Example feedback (remove comments from JSON) ➡

# Add feedback
curl -X POST \
  'https://api.astor.ai/v1/tag-receipt \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer ey...' \
  -H 'Accept: application/json' \
  -d '
      {
        "accRef": "9aba0ed9-2f3b-4673-b86e-802acf030ef5",
        "accounted": {
          "tag": "ValidatedWaitingConfirm"
        },
        "accImage": "9aba0ed9-2f3b-4673-b86e-802acf030ef5",
        "accounting": [
          // The first field is an AccountingResults object.
          // It is ok to have all empty arrays in this object.
          // Only add data when it has been verified by the user.
          {
            "OrgInfo": [],
            // This array is optional and can be left empty.
            "Nets": [
              {
                "amount": 277.28,
                "strength": "High"
              }
            ],
            // This array is optional and can be left empty.
            "VATTotals": [
              {
                "Amount": 65.72,
                "Percent": 24
              }
            ],
            "Payment": [],
            // This array is optional and can be left empty.
            "Time": [
              "10:25:00"
            ],
            // This array is optional and can be left empty.
            "VATBreakdowns": [
              {
                "Net": 277.28,
                "VAT": {
                  "Amount": 65.72,
                  "Percent": 24
                },
                "Total": 343
              }
            ],
            // This array is optional and can be left empty.
            "Totals": [
              {
                "amount": 343,
                "strength": "High"
              }
            ],
            // This array is optional and can be left empty.
            "Date": [
              "2020-04-17"
            ],
            // This array is optional and can be left empty.
            "Currency": [
              "SEK"
            ],
            // This array is optional and can be left empty.
            "Id": [],
            // This array is optional and can be left empty.
            "InvoiceInfo": [{
              // The PaymentRefNumber is also called OCR or KID
              "PaymentRefNumber": "29107109170971",
              "InvoiceRef": "142",
              "BankAccount": {
                "Type": "Bankgiro",
                "Info": "237-3927"
              },
              "PaymentDueDate": "2018-05-14",
              "InvoiceDate": "2018-04-20"
            }]
          },
          // The following array should be populated in order to
          // train the posting list for the particular company
          // associated with the voucher.
          // The sum of all Debets must match the sum of all Credits.
          [
            {
              "DebetCredit": {
                // Left means Debet, right means Credit

                "Right": 343
              },
              // Populate the AccountName if you use text as the identifier
              // for your accounts, or AccountNumber if you use a number
              // as the identifier.
              "AccountName": "",
              "AccountNumber": 2018
            },
            {
              "DebetCredit": {
                "Left": 65.72
              },
              "AccountName": "",
              "AccountNumber": 2640
            },
            {
              "DebetCredit": {
                "Left": 277.28
              },
              "AccountName": "",
              "AccountNumber": 5400
            }
          ],
          // The following can be left exactly as-is.  It is extra
          // information for deductable meals, meetings etc.
          {
            "attendees": []
          }
        ]
      }
     '
Followers: 0
Resources:
Product Website Terms of use
API Creator:
Rapid account: Astor AI
Astor AI
astor-ai
Log In to Rate API
Rating: 5 - Votes: 1