Skip to content

Node.js example for the Parserdata Financial Data Extraction API.

License

Notifications You must be signed in to change notification settings

parserdata/parserdata-nodejs-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js Parserdata API

Parserdata Node.js API Example

Node.js example for using the Parserdata Financial Data Extraction API to extract structured data from invoices and financial documents.

This repository demonstrates how to upload a document using multipart/form-data and receive clean, structured JSON in response.


✨ Features

  • Upload PDFs and documents via multipart form
  • Extract invoice data using natural-language prompts
  • Simple Node.js example using node-fetch
  • Works with any invoice or financial document

📦 Requirements

  • Node.js 16+
  • A Parserdata API key

🔑 Get an API Key

  1. Sign up at https://parserdata.com
  2. Create an API key in your dashboard
  3. Export it as an environment variable:
export PARSERDATA_API_KEY="YOUR_API_KEY"

Windows (PowerShell):

$env:PARSERDATA_API_KEY="YOUR_API_KEY"

📥 Installation

Clone the repository and install dependencies:

git clone https://github.com/parserdata/parserdata-nodejs-example.git
cd parserdata-nodejs-example
npm install

Dependencies used:

  • node-fetch

  • form-data

Basic Usage

Create a file called parse-invoice.mjs:

import fs from "fs";
import fetch from "node-fetch";
import FormData from "form-data";

const apiKey = process.env.PARSERDATA_API_KEY;
const url = "https://api.parserdata.com/v1/extract";

async function run() {
  const form = new FormData();

  form.append(
    "prompt",
    "Extract invoice number, invoice date, supplier name, total amount, and line items (description, quantity, unit price, net amount)."
  );

  form.append(
    "options",
    JSON.stringify({
      return_schema: false,
      return_selected_fields: false
    })
  );

  form.append("file", fs.createReadStream("./invoice.pdf"));

  const res = await fetch(url, {
    method: "POST",
    headers: {
      "X-API-Key": apiKey,
      ...form.getHeaders()
    },
    body: form
  });

  const data = await res.json();
  console.log(JSON.stringify(data, null, 2));
}

run();

Run the script:

node parse-invoice.mjs

Response

The API returns structured JSON containing the extracted fields, for example:

{
  "invoice_number": "INV-2024-001",
  "invoice_date": "2024-01-12",
  "supplier_name": "Acme Corp",
  "total_amount": 1234.56,
  "line_items": [
    {
      "description": "Consulting services",
      "quantity": 1,
      "unit_price": 1234.56,
      "net_amount": 1234.56
    }
  ]
}

How extraction works

Parserdata uses natural-language prompts to understand what data you want to extract. You can freely modify the prompt field to match your document structure or schema needs.

License

MIT

About

Node.js example for the Parserdata Financial Data Extraction API.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published