Tip: Scroll down to see the ouput json
Our API expects the image to be in base64
format.
So let's load it and convert it to base64
.
import fs from "fs";
// use {encoding: "base64"} to load the image already as base64
const base64_image = fs.readFileSync("receipt.jpg", { encoding: "base64" });
Next we need to send it to our api.
https://www.line-items.com/api/scanner
application/json
<api-key>
{"receipt64":base64_image}
const response = await fetch("https://www.line-items.com/api/scanner", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": "<api-key>",
},
body: JSON.stringify({
receipt64: base64_image,
}),
});
const scannedReceipt = await response.json();
console.log("scannedReceipt", scannedReceipt);
Tip: Our api always returns a JSON. Even if something fails.
{
"receipt": {
"storeName": "Lollipop Park",
"storeAddress": "Tennispointstraße 1, 4061 Pasching",
"storePhoneNumber": null,
"storeWebpage": "www.lollipark.at",
"storeType": "Amusement Park/Recreation Center",
"lineItems": [
{
"description": "TK Erwachsene",
"unitPrice": 6,
"totalPrice": 12,
"currency": "EUR",
"quantity": 2,
"productType": "Ticket for Adults"
},
{
"description": "TK Kind",
"unitPrice": 12,
"totalPrice": 12,
"currency": "EUR",
"quantity": 1,
"productType": "Ticket for Child"
}
],
"date": "2023-10-28T10:43:36"
},
"error": false,
"status": 200,
"message": "Success. Looks like everything was working nicely!"
}