Tutorial · Automation

How to Automate Invoice Parsing in n8n

By Othmane M., founder of DocuParse API

2026-05-27 · 6 min readLast updated: 2026-10-20
📧 Email Trigger

New invoice arrives

→
🔗 HTTP Request

Submit, wait, fetch the result

→
⚙️ Set Fields

data.merchant, data.total, data.date

→
📊 Google Sheets

New row appended

The complete workflow you'll build in this guide — importable in one click

n8n is a workflow automation tool that connects apps and APIs without writing code. This guide shows how to build a workflow that takes an invoice file and automatically extracts the structured data using DocuParse API.

What We're Building

A workflow that:

  1. Triggers when a new invoice arrives (email attachment, Google Drive, or manual trigger)
  2. Calls DocuParse API to extract the invoice data
  3. Writes the extracted fields to Google Sheets (or any other destination)

Total setup time: 15–20 minutes.

What You Need

  • n8n (cloud or self-hosted)
  • A DocuParse API account — sign up free at docuparseapi.com
  • A Google account (for Google Sheets output — or substitute any other destination node)

Step 1: Get Your API Key

  1. Sign up at docuparseapi.com
  2. Go to Dashboard → API Keys
  3. Create a new key and copy it immediately (shown only once)

Don't have a DocuParse API key yet?

Get 20 documents/month — free forever — no credit card.

Sign up — get a free API key

Step 2: Create the Workflow

Node 1: Trigger

For testing, use the Manual Trigger node. For production, replace with:

  • Email Trigger (IMAP): fires when a new email arrives with an attachment
  • Google Drive Trigger: fires when a new file appears in a folder
  • Webhook: fires when your app posts an invoice file

Node 2: HTTP Request (DocuParse API call)

Add an HTTP Request node with these settings:

Method: POST
URL: https://docuparseapi.com/api/v1/extract
Authentication: Header Auth
  Header Name: Authorization
  Header Value: Bearer YOUR_API_KEY_HERE
Body Content Type: Form-Data/Multipart
Body Parameters:
  Name: file
  Value: [binary data from previous node]
  Type: File

If your previous node outputs a file (e.g., an email attachment), set the file value to the binary output of that node using the expression: {{ $binary.data }}.

Name this node Submit Document. It returns a document_id, not the extracted fields, so add three more nodes to fetch the result:

  1. A Wait node — wait 5 seconds so extraction can finish.
  2. An HTTP Request node named Get Result:
Method: GET
URL: https://docuparseapi.com/api/v1/documents/{{ $('Submit Document').item.json.document_id }}
Authentication: Header Auth (same credential)
  1. An IF node named Completed? — condition: {{ $json.status }} equals completed. True → map fields. False → back to the Wait node (add a second IF that stops with an error when status equals failed).
HTTP Request
MethodPOST
URLhttps://docuparseapi.com/ api/v1/extract
AuthenticationHeader Auth
Header NameAuthorization
Header ValueBearer ••••••••••••
Body TypeMultipart/Form-Data
Field Namefile
Field Value{{ $binary.data }}

Your Submit Document node should look like this. The Get Result node then calls GET https://docuparseapi.com/api/v1/documents/{id}.

Node 3: Parse the Response

Add a Set node after the Completed? true branch to map the fields you need:

merchant  →  {{ $json.data.merchant }}
total     →  {{ $json.data.total }}
tax       →  {{ $json.data.tax }}
currency  →  {{ $json.data.currency }}
date      →  {{ $json.data.date }}
invoice_id → {{ $json.data.invoice_id }}

Node 4: Write to Google Sheets

Add a Google Sheets node:

  • Operation: Append
  • Sheet: your invoice tracking sheet
  • Map the fields from the Set node to your sheet columns

The Complete Workflow (JSON Import)

You can import this directly into n8n:

⬇ Skip the setup — import the complete workflow directly

Copy the JSON below and paste it into n8n:
n8n → New Workflow → ⋮ (menu) → Import from JSON

json · 37 lines
{
  "name": "Invoice Parser — DocuParse API",
  "nodes": [
    { "name": "Manual Trigger", "type": "n8n-nodes-base.manualTrigger", "typeVersion": 1, "position": [240, 300], "parameters": {} },
    { "name": "Submit Document", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4, "position": [460, 300],
      "parameters": { "method": "POST", "url": "https://docuparseapi.com/api/v1/extract",
        "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth",
        "sendBody": true, "contentType": "multipart-form-data",
        "bodyParameters": { "parameters": [ { "parameterType": "formBinaryData", "name": "file", "inputDataFieldName": "data" } ] } } },
    { "name": "Wait", "type": "n8n-nodes-base.wait", "typeVersion": 1, "position": [680, 300], "parameters": { "amount": 5, "unit": "seconds" } },
    { "name": "Get Result", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4, "position": [900, 300],
      "parameters": { "method": "GET", "url": "=https://docuparseapi.com/api/v1/documents/{{ $('Submit Document').item.json.document_id }}",
        "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth" } },
    { "name": "Completed?", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [1120, 300],
      "parameters": { "conditions": { "string": [ { "value1": "={{ $json.status }}", "value2": "completed" } ] } } },
    { "name": "Failed?", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [1120, 500],
      "parameters": { "conditions": { "string": [ { "value1": "={{ $json.status }}", "value2": "failed" } ] } } },
    { "name": "Stop on Failure", "type": "n8n-nodes-base.stopAndError", "typeVersion": 1, "position": [1340, 500],
      "parameters": { "errorMessage": "DocuParse API extraction failed" } },
    { "name": "Map Fields", "type": "n8n-nodes-base.set", "typeVersion": 1, "position": [1340, 300],
      "parameters": { "values": { "string": [
        { "name": "merchant", "value": "={{ $json.data.merchant }}" },
        { "name": "total", "value": "={{ $json.data.total }}" },
        { "name": "tax", "value": "={{ $json.data.tax }}" },
        { "name": "currency", "value": "={{ $json.data.currency }}" },
        { "name": "date", "value": "={{ $json.data.date }}" },
        { "name": "invoice_id", "value": "={{ $json.data.invoice_id }}" } ] } } }
  ],
  "connections": {
    "Manual Trigger": { "main": [ [ { "node": "Submit Document", "type": "main", "index": 0 } ] ] },
    "Submit Document": { "main": [ [ { "node": "Wait", "type": "main", "index": 0 } ] ] },
    "Wait": { "main": [ [ { "node": "Get Result", "type": "main", "index": 0 } ] ] },
    "Get Result": { "main": [ [ { "node": "Completed?", "type": "main", "index": 0 } ] ] },
    "Completed?": { "main": [ [ { "node": "Map Fields", "type": "main", "index": 0 } ], [ { "node": "Failed?", "type": "main", "index": 0 } ] ] },
    "Failed?": { "main": [ [ { "node": "Stop on Failure", "type": "main", "index": 0 } ], [ { "node": "Wait", "type": "main", "index": 0 } ] ] }
  }
}

In the Manual Trigger test, attach a file as binary property "data". In production, replace the trigger with Gmail, Google Drive or a webhook trigger.

Handling Errors in n8n

The Failed? IF node after Get Result checks the document status:

  • Condition: {{ $json.status }} equals failed
  • True branch: stop with an error, or send a notification (Slack, email)
  • False branch: back to the Wait node

If the Submit Document request itself fails, its response carries {{ $json.error.code }}.

Common errors and what they mean:

  • LIMIT_EXCEEDED — you've hit your monthly document limit; upgrade your plan
  • EXTRACTION_FAILED — the document couldn't be parsed; check the file quality
  • UNSUPPORTED_FILE_TYPE — only PDF, JPG, PNG are supported

Real Workflow: Email Invoice → Google Sheet

Gmail Trigger
→
Filter
→
Submit + Get Result
→
IF completed
→
Google Sheets row
→
Slack / Email

This is the most common use case for small businesses:

  1. Email Trigger (IMAP): Watch an email inbox for supplier invoices
  2. Filter: Check if the email has a PDF attachment
  3. HTTP Request: Send the attachment to DocuParse API, wait, then fetch the result with GET /api/v1/documents/{id}
  4. IF: Check status === "completed"
  5. Google Sheets: Append a new row with extracted fields
  6. Slack/Email: Send a notification that the invoice was processed

With this workflow, every supplier invoice that arrives in your inbox is automatically extracted and logged to a spreadsheet — no manual data entry.

Next Steps

Your n8n workflow is ready. Your API key isn't.

Get 20 documents/month — free forever.
No credit card. No expiry. Add your key and run the workflow.

Sign up — get a free API key

More from the blog

All posts →