Veryfi SDK for Node.js

Table of Contents
veryfi-nodejs is a Node.js module for communicating with the Veryfi OCR API
Installation
Install from npm, a package manager for Javascript.
npm i @veryfi/veryfi-sdk
You may need to run the above command with sudo.
Getting Started
Obtaining Client ID and user keys
If you don’t have an account with Veryfi, please go ahead and register here: https://app.veryfi.com/signup/api/
Node.js API Client Library
The veryfi library can be used to communicate with Veryfi API. All available functionality is described here: https://veryfi.github.io/veryfi-nodejs/
Below is a sample script using Veryfi for OCR and extracting data from a document:
const Client = require('@veryfi/veryfi-sdk');
const client_id = 'your_client_id';
const client_secret = 'your_client_secret';
const username = 'your_username';
const api_key = 'your_password';
const categories = ['Grocery', 'Utilities', 'Travel'];
const file_path = './test/receipt.png';
This submits a document for processing (3-5 seconds for a response)
let veryfi_client = new Client(client_id, client_secret, username, api_key);
let response = veryfi_client.process_document(file_path, categories).then(response => {
console.log(response)
});
…or with a URL
let response = veryfi_client.process_document_from_url(url, null, categories, false, false, some_id).then(response => {
console.log(response)
});
Thinking Mode reviews receipt and invoice extraction before the response is returned. Pass light or deep, and leave it out for the standard pipeline. It has to be enabled on the account. See Process a Document.
let response = veryfi_client.process_document(file_path, categories, false, {
thinking: 'light'
}).then(response => {
console.log(response)
});
const document_id = '123';
await veryfi_client.create_line_item(document_id, { description: 'Milk', total: 3.5 });
await veryfi_client.get_document_line_items(document_id);
await veryfi_client.add_tag(document_id, 'reviewed');
await veryfi_client.get_document_tags(document_id);
await veryfi_client.process_contract_from_url('https://cdn.example.com/contract.pdf');
await veryfi_client.process_markdown_document_from_url('https://cdn.example.com/invoice.pdf');
await veryfi_client.classify_document_from_url('https://cdn.example.com/receipt.jpg', null, {
document_types: ['receipt', 'invoice']
});
await veryfi_client.extract_document_from_url('https://cdn.example.com/receipt.jpg', null, ['receipt', 'invoice']);
Response
{
"account_number": "test1",
"accounting_entry_type": "debit",
"balance": null,
"barcodes": [
{
"data": "101785617711518",
"type": "CODE128"
}
],
"bill_to": {
"address": null,
"email": null,
"name": null,
"parsed_address": null,
"phone_number": null,
"reg_number": null,
"vat_number": null
},
"cashback": null,
"category": "Supplies",
"created_date": "2024-10-31 14:38:27",
"currency_code": "USD",
"custom_fields": {
"box_number": null,
"dsadasas": "dasdsadas",
"foo": "bar"
},
"date": "2018-10-17 09:03:00",
"default_category": "Job Supplies",
"delivery_date": null,
"delivery_note_number": null,
"discount": null,
"document_reference_number": null,
"document_title": null,
"document_type": "receipt",
"due_date": null,
"duplicate_of": null,
"exch_rate": 1,
"external_id": null,
"final_balance": null,
"guest_count": null,
"id": 255371329,
"img_blur": false,
"img_file_name": "255371329.png",
"img_thumbnail_url": "https://scdn.veryfi.com/receipts/919ba4778c039560/d9477032-8537-41cf-97dd-56cb1443a576/thumbnail.png?Expires=1730386417&Signature=VNRx8OISmHUsbPk3YAItcUteEAb4GyLxHTplgCxDxGD2NDE05I7XG~92ikhZhz6oTfCPGqLc7l5Zw0PmDD7di07ZCWRqkpB2OSPUU9ZlHbDLnpenGC7QscEaf8mPb8k0UDKXMY7gw8GCCoRS7IirMnN8aIpaKeRvukIKYCJMqEkX9ncf247BcLyYvnOV20gLieIT1~mofcCebUakr3hBSAbThN0vwYNDXSqth-IpNpDAMcm-nU71KlJWFqdRv4~m3NljwhFkXy1eTK3JiV97EfZJ-Nj~MUxBKWhIjBS~~l-Dp218ogv53Ws8llP5r1RiRrdgqIOtx-8xKa21WU8vbQ__&Key-Pair-Id=APKAJCILBXEJFZF4DCHQ",
"img_url": "https://scdn.veryfi.com/receipts/919ba4778c039560/d9477032-8537-41cf-97dd-56cb1443a576/8e9aebdd-d4f6-4fec-97c8-237dc5bd190d.png?Expires=1730386417&Signature=HTydoDEasZLN7C0QTj-flLCqUqruI3ereSbllb2SEDHrxQTXZPqQ99HE87E5OsWzDmtNumGXYs4UFPjSSOOidUy38EbmyOEljp0VFxPwXMMrJtoVGGShIkTHg-desK3r0fx6xy9l~IX16SEtNCQyZLrzkjTRp0xU9kM1kVuBueW6JewxXUfiIlPu~ITwbwr7PtqRG6uHB3X1myrRXBSv-arbTaLvCrBrmIMGz0gaPH5dA~ehhDSIRvxaKTNTWX-MBloNHfhz~v7xYJyFooDwetyxV968JqGlR-Jx6EAillWbnuflfH5R~VRr~CAtbCsz9gM6q2nqVXPhDDRUl~hrkA__&Key-Pair-Id=APKAJCILBXEJFZF4DCHQ",
"incoterms": null,
"insurance": null,
"invoice_number": "17717",
"is_approved": false,
"is_blurry": [
false
],
"is_document": true,
"is_duplicate": false,
"is_money_in": false,
"is_transaction": false,
"license_plate_number": null,
"line_items": [
{
"category": "Supplies",
"country_of_origin": null,
"custom_fields": {},
"date": null,
"description": "SNIP LEFT <A>\nWISS LEFT-CUT SNIPS",
"discount": 4,
"discount_price": null,
"discount_rate": null,
"end_date": null,
"full_description": "SNIP LEFT <A>\nWISS LEFT-CUT SNIPS",
"gross_total": null,
"hsn": null,
"id": 1146544820,
"lot": null,
"manufacturer": null,
"net_total": null,
"normalized_description": null,
"order": 0,
"price": null,
"quantity": 1,
"reference": null,
"section": null,
"sku": "037103136480",
"start_date": null,
"subtotal": null,
"tags": [
"line_items_total_greater_than_1"
],
"tax": null,
"tax_code": null,
"tax_rate": null,
"text": "037103136480 SNIP LEFT <A>\t9.97\nWISS LEFT-CUT SNIPS$4.00",
"total": 9.97,
"type": "product",
"unit_of_measure": null,
"upc": null,
"weight": null
},
{
"category": "Supplies",
"country_of_origin": null,
"custom_fields": {},
"date": null,
"description": "MILW5PCKBLDG <A>\nMKE 5PK GENERAL PURPOSE BLADES",
"discount": null,
"discount_price": null,
"discount_rate": null,
"end_date": null,
"full_description": "MILW5PCKBLDG <A>\nMKE 5PK GENERAL PURPOSE BLADES",
"gross_total": null,
"hsn": null,
"id": 1146544822,
"lot": null,
"manufacturer": null,
"net_total": null,
"normalized_description": null,
"order": 1,
"price": null,
"quantity": 1,
"reference": null,
"section": null,
"sku": "045242268061",
"start_date": null,
"subtotal": null,
"tags": [
"line_items_total_greater_than_1"
],
"tax": null,
"tax_code": null,
"tax_rate": null,
"text": "045242268061 MILW5PCKBLDG <A>\t1.18\nMKE 5PK GENERAL PURPOSE BLADES",
"total": 1.18,
"type": "product",
"unit_of_measure": null,
"upc": null,
"weight": null
},
{
"category": "Supplies",
"country_of_origin": null,
"custom_fields": {},
"date": null,
"description":
提示:代码过长已自动截断
Updating a document
let new_vendor = {"name": "Starbucks", "address": "123 Easy Str, San Francisco, CA 94158"};
let category = "Meals & Entertainment";
let new_total = 11.23;
veryfi_client.update_document(id=12345,
{
'vendor': new_vendor,
'category': new_category,
'total': new_total
})
.then(response => {
console.log(response)
});
Need help?
Visit https://docs.veryfi.com/ to access integration guides and usage notes in the Veryfi API Documentation Portal
If you run into any issue or need help installing or using the library, please contact [email protected].
If you found a bug in this library or would like new features added, then open an issue or pull requests against this repo!
Tutorial Video

评论