Getting started
This guide will help you get started with the Mindee Node.js SDK library to easily extract data from your documents.
The Node.js SDK supports invoice and receipt OCR APIs.
You can view the source code on GitHub and the package on npm.
Install the mindee node.js helper library
The easiest way to install the mindee node.js helper is from NPM. You can run the command below from your project directory to install the library:
npm install mindee
Instantiate your Client
The mindee.Client needs your API credentials. You can either pass these directly to the constructor (see the code below) or via environment variables.
const { Client } = require("mindee");
const mindeeClient = new Client({
invoiceToken: "yourInvoiceApiKey",
receiptToken: "yourReceiptApiKey",
});
The mindee.Client can take multiple parameters. Some of those parameters can also be set using environment variables. For any parameter, if the env variable and the parameter are both defined, the parameter used will be the one set in the mindee.Client. This is the list of the different parameters:
Parameters | Environment variable | Details |
---|---|---|
invoiceToken | MINDEE_INVOICE_TOKEN | Invoice API key |
receiptToken | MINDEE_RECEIPT_TOKEN | Receipt API key |
throwOnError | (true by default) If true, the SDK will throw an error when the API response status is different from 200 | |
debug | MINDEE_DEBUG | false by default) If true, logging will be in debug mode |
We suggest storing your credentials as environment variables. Why? You'll never have to worry about committing your credentials and accidentally posting them somewhere public.
Parse a document
const { Client } = require("mindee");
const mindeeClient = new Client({
invoiceToken: "yourInvoiceApiKey",
receiptToken: "yourReceiptApiKey"
});
mindeeClient.invoice.parse(
{
input : "invoice.pdf",
inputType : 'path'
}
)
.then((res) => {
console.log(res.invoice);
})
.catch((err) => {
console.error(err);
});
mindeeClient.receipt.parse(
{
input : "receipt.jpg",
inputType : 'path',
}
)
.then((res) => {
console.log(res.receipt);
})
.catch((err) => {
console.error(err);
});
Input types
You can pass your input file in three ways:
From file path
mindeeClient.invoice.parse(
{
input : "invoice.pdf",
inputType : 'path',
}
)
.then((res) => {
console.log(res.invoice);
})
.catch((err) => {
console.error(err);
});
From a file object
const fs = require("fs");
const file = fs.createReadStream("./path/to/img/or/pdf");
mindeeClient.invoice.parse(
{
input : file,
inputType : 'stream',
}
)
.then((res) => {
console.log(res.invoice);
})
.catch((err) => {
console.error(err);
});
From a base64
const base64 = fs.readFileSync("./inv.pdf", {
encoding: "base64",
});
mindeeClient.invoice.parse(
{
input : base64,
inputType : 'base64',
}
)
.then((res) => {
console.log(res.invoice);
})
.catch((err) => {
console.error(err);
});
Questions?
Updated about 1 month ago