# Extract invoice data and line items to JSON

**Use case:** 

Turns an invoice into structured JSON: vendor, invoice number, invoice and due dates, payment terms, purchase order, subtotal, tax, total, currency and every line item with quantity, unit price and amount. The example runs on an inline sample invoice (a data: URL), so swap in your own invoice PDF or DOCX URLs. Free rules extractor, no model, no API key.

## Input

```json
{
  "urls": [
    "data:text/markdown;base64,IyBJTlZPSUNFCgpOb3J0aHdpbmQgT2ZmaWNlIFN1cHBseSBDby4KMTIwMCBIYXJib3IgU3RyZWV0LCBTdWl0ZSA0MDAKUG9ydGxhbmQsIE9SIDk3MjAxCmJpbGxpbmdAbm9ydGh3aW5kLXN1cHBseS5leGFtcGxlLmNvbQoKSW52b2ljZSBudW1iZXI6IElOVi0yMDI2LTA0MTcKSW52b2ljZSBkYXRlOiAyMDI2LTA5LTMwCkR1ZSBkYXRlOiAyMDI2LTEwLTMwClBheW1lbnQgdGVybXM6IE5ldCAzMApQdXJjaGFzZSBvcmRlcjogUE8tODgyMTMKCkJpbGwgdG86IENhc2NhZGlhIENpdmlsIEVuZ2luZWVyaW5nLCA0NTUgUGluZSBBdmVudWUsIFNlYXR0bGUsIFdBIDk4MTAxCgp8IERlc2NyaXB0aW9uIHwgUXVhbnRpdHkgfCBVbml0IHByaWNlIHwgQW1vdW50IHwKfC0tLXwtLS18LS0tfC0tLXwKfCBBNCBjb3B5IHBhcGVyLCA4MCBnLCBib3ggb2YgNSByZWFtcyB8IDEyIHwgJDM4LjUwIHwgJDQ2Mi4wMCB8CnwgVG9uZXIgY2FydHJpZGdlLCBibGFjaywgSFAgMjZYIHwgNCB8ICQxMjkuMDAgfCAkNTE2LjAwIHwKfCBFcmdvbm9taWMgb2ZmaWNlIGNoYWlyLCBtb2RlbCBLMiB8IDIgfCAkMjg5LjAwIHwgJDU3OC4wMCB8CnwgRGVsaXZlcnkgYW5kIGhhbmRsaW5nIHwgMSB8ICQ0NS4wMCB8ICQ0NS4wMCB8CgpTdWJ0b3RhbDogJDEsNjAxLjAwClNhbGVzIHRheCAoMCUpOiAkMC4wMApUb3RhbCBkdWU6ICQxLDYwMS4wMApDdXJyZW5jeTogVVNECg=="
  ],
  "schema": {
    "type": "object",
    "properties": {
      "vendorName": {
        "type": "string",
        "description": "Name of the company issuing the invoice"
      },
      "invoiceNumber": {
        "type": "string",
        "description": "The invoice number"
      },
      "invoiceDate": {
        "type": "string",
        "format": "date",
        "description": "Date the invoice was issued"
      },
      "dueDate": {
        "type": "string",
        "format": "date",
        "description": "Payment due date"
      },
      "paymentTerms": {
        "type": "string",
        "description": "Payment terms, e.g. Net 30"
      },
      "purchaseOrder": {
        "type": "string",
        "description": "Customer purchase order number"
      },
      "customerName": {
        "type": "string",
        "title": "Bill to",
        "description": "The customer being invoiced (Bill to)"
      },
      "subtotal": {
        "type": "number",
        "description": "Subtotal before tax"
      },
      "tax": {
        "type": "number",
        "description": "Sales tax amount"
      },
      "total": {
        "type": "number",
        "description": "Total due including tax"
      },
      "currency": {
        "type": "string",
        "description": "Currency code, e.g. USD"
      },
      "lineItems": {
        "type": "array",
        "description": "The invoice line items",
        "items": {
          "type": "object",
          "properties": {
            "description": {
              "type": "string",
              "description": "Item description"
            },
            "quantity": {
              "type": "integer",
              "description": "Quantity"
            },
            "unitPrice": {
              "type": "number",
              "description": "Unit price"
            },
            "amount": {
              "type": "number",
              "description": "Line amount"
            }
          }
        }
      }
    }
  },
  "extractor": "rules",
  "modelTier": "fast",
  "maxInputTokens": 40000,
  "maxConcurrency": 2,
  "includeMarkdown": false,
  "maxFileSizeMb": 25,
  "downloadTimeoutSecs": 20
}
```

## Output

```json
{
  "filename": {
    "label": "File",
    "format": "text"
  },
  "title": {
    "label": "Title",
    "format": "text"
  },
  "pages": {
    "label": "Pages",
    "format": "number"
  },
  "extractionMethod": {
    "label": "Method",
    "format": "text"
  },
  "modelTier": {
    "label": "Tier",
    "format": "text"
  },
  "filledFields": {
    "label": "Filled",
    "format": "number"
  },
  "totalFields": {
    "label": "Fields",
    "format": "number"
  },
  "overallConfidence": {
    "label": "Confidence",
    "format": "number"
  },
  "data": {
    "label": "Extracted JSON",
    "format": "object"
  },
  "modelCostUsdEstimate": {
    "label": "Model cost (USD)",
    "format": "number"
  },
  "error": {
    "label": "Error",
    "format": "text"
  }
}
```

## How it works

### 1. Sign up on Apify or log in

The PDF & Document to JSON Extractor (AI) — Invoices, Forms Actor is ready to run with the inputs already set for "Extract invoice data and line items to JSON". [Sign up or log in](https://console.apify.com/create-task-from-example/laoPSlxODIPLLPt3b) and you'll land in Apify Console with a copy of this exact task.

### 2. Start the "Extract invoice data and line items to JSON" task

The PDF & Document to JSON Extractor (AI) — Invoices, Forms Actor will start running based on the input automatically. You can also change all the input fields, like document urls, JSON Schema of the object to extract, and more, to match your specific use case.

### 3. Receive the "Extract invoice data and line items to JSON" output

Monitor the progress in real time. You will be notified as soon as your dataset is complete and ready for review. Each result includes data such as file, title, pages, and more.

### 4. Integrate into your workflow

The final output is delivered in JSON, CSV, or Excel format, ready to be plugged into your workflow. You can also [run the "Extract invoice data and line items to JSON" task via API](https://apify.com/owlabee/document-to-json-extractor.md).

## About this Actor

This example demonstrates how to use [PDF & Document to JSON Extractor (AI) — Invoices, Forms](https://apify.com/owlabee/document-to-json-extractor.md) with a specific input configuration. Visit the [Actor detail page](https://apify.com/owlabee/document-to-json-extractor.md) to learn more, explore other use cases, and run it yourself.


## How to integrate an Actor?

This Task's input is already configured above. Use it as-is rather than inventing a new one.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For full API examples (JavaScript, Python, CLI, MCP, OpenAPI), see this Task's Actor page: https://apify.com/owlabee/document-to-json-extractor.md

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).
