Skip to content

mindee/mindee-api-php

Repository files navigation

License: MIT GitHub Workflow Status Packagist Version Downloads

Mindee API Helper Library for PHP

Quickly and easily connect to Mindee's API services using PHP.

Quick Start

Here's the TL;DR of getting started.

First, get an API Key

If you do not have them, you'll need the following packages on your system:

Then, install this library:

composer require mindee/mindee

Finally, PHP away!

Loading a File and Parsing It

Global Documents

<?php

use Mindee\Client;
use Mindee\Product\Invoice\InvoiceV4;

// Init a new client
$mindeeClient = new Client("my-api-key");

// Load a file from disk
$inputSource = $mindeeClient->sourceFromPath("/path/to/the/file.ext");

// Parse the file
$apiResponse = $mindeeClient->parse(InvoiceV4::class, $inputSource);

// Print a brief summary of the parsed data
echo strval($apiResponse->document);

Note: Files can also be loaded from:

A PHP File compatible file:

$inputDoc = $mindeeClient->sourceFromFile($myFile);

A URL (HTTPS only):

$inputDoc = $mindeeClient->sourceFromUrl("https://files.readme.io/a74eaa5-c8e283b-sample_invoice.jpeg");

A base64-encoded string, making sure to specify the extension of the file name:

$inputDoc = $mindeeClient->sourceFromB64($myInputString, "my-file-name.ext");

Raw bytes, making sure to specify the extension of the file name:

$inputDoc = $mindeeClient->sourceFromBytes($myRawBytesSequence, "my-file-name.ext");

Region-Specific Documents

use Mindee\Client;
use Mindee\Product\Us\BankCheck\BankCheckV1;

// Init a new client
$mindeeClient = new Client("my-api-key");

// Load a file from disk
$inputSource = $mindeeClient->sourceFromPath("/path/to/the/file.ext");

// Parse the file
$apiResponse = $mindeeClient->parse(BankCheckV1::class, $inputSource);

// Print a brief summary of the parsed data
echo strval($apiResponse->document);

Custom Document (API Builder)

use Mindee\Client;
use Mindee\Product\Us\BankCheck\BankCheckV1;

// Init a new client
$mindeeClient = new Client("my-api-key");

// Load a file from disk
$inputSource = $mindeeClient->sourceFromPath("/path/to/the/file.ext");

// Parse the file
$apiResponse = $mindeeClient->parse(BankCheckV1::class, $inputSource);

// Print a brief summary of the parsed data
echo strval($apiResponse->document);

Full PDF support

Some features such as Invoice Splitter auto-extraction & Multi Receipts auto-extraction require the ImageMagick library, which in turn requires GhostScript.

Unix

ImageMagick is usually bundled with most installations. If not, you can install it using your distribution's package manager.

More details here.

Ghostscript can be installed from the website download page, or if using an apt compatible distribution:

sudo apt-get update
sudo apt-get install -y ghostscript

In some cases, you might also want to authorize the ImageMagick policy to edit PDF files:

DQT='"'
SRC="rights=${DQT}none${DQT} pattern=${DQT}PDF${DQT}"
RPL="rights=${DQT}read|write${DQT} pattern=${DQT}PDF${DQT}"
sudo sed -i "s/$SRC/$RPL/" /etc/ImageMagick-6/policy.xml

MacOS

Brew will be required for this install.

brew update
brew install imagemagick
pecl install imagick # Might not be needed in some instances. Do not try to install before installing PHP & Pecl.

Windows

You can install Ghostscript by downloading it, or simply by using Chocolatey.

choco install ghostscript --version 10.03.1 -y

⚠️ Important note if you are using Windows The gs alias might not be available by default, but it is possible to bind it fairly simply by either adding gswin32c.exe or gswin64c.exe to your $PATH and then adding a symlink in powershell using:

New-Item -ItemType SymbolicLink -Path "C:\Windows\gs.exe" -Target "C:\Program Files\gs\gs10.03.1\bin\gswin64c.exe"
New-Item -ItemType SymbolicLink -Path "C:\Windows\gs" -Target "C:\Program Files\gs\gs10.03.1\bin\gswin64c.exe"

Further Reading

Complete details on the working of the library are available in the following guides:

You can view the source code on GitHub.

You can also take a look at the Reference Documentation.

License

Copyright © Mindee

Available as open source under the terms of the MIT License.

Questions?

Join our Slack