Invoice & Document Data Extraction to Excel via Nanonets OCR - n8n Workflow

Automate invoice data extraction using Nanonets OCR and export results directly to Excel. This powerful n8n workflow processes complex line items efficiently and is one of the best n8n templates for accounting automation.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Accounting departments needing automated AP processing.
Operations teams looking to digitize paper records.
Developers building document processing APIs using n8n.
Users seeking robust n8n templates for custom data manipulation.

Overview

Handling unstructured documents like invoices and receipts is a major bottleneck in automation. This solution provides a complete, serverless method for integrating advanced Optical Character Recognition (OCR) into your existing processes using n8n. By leveraging Nanonets, this specific n8n workflow ensures high accuracy in data capture, including intricate line items and complex table structures. The core value of this n8n workflow lies in its custom data transformation layer (the Code n8n node), which standardizes the varying JSON output from the OCR service into a consistent, actionable format, ready for immediate export to an Excel file. This makes it an invaluable addition to any set of n8n templates focused on finance or document management.

How it Works

This automation is initiated by an incoming file upload via an n8n trigger:


  1. Incoming Document: The n8n workflow starts when the Webhook n8n node receives a POST request containing a binary file (the invoice or document).

  2. OCR Submission: An HTTP Request n8n node immediately submits the binary file to the specified Nanonets workflow API for processing.

  3. Document ID Capture: A subsequent Code n8n node parses the initial API response to extract the crucial documentid required for retrieval.

  4. Wait Period: The Wait n8n node pauses the execution for 15 seconds, allowing the Nanonets OCR engine time to process and extract the fields.

  5. Retrieve Processed Data: A second HTTP Request n8n node queries the Nanonets API using the documentid to fetch the fully processed structured data.

  6. Data Structuring: The critical Code1 n8n node executes custom JavaScript logic. It parses the complex Nanonets JSON, isolates header fields, identifies line items within the embedded tables, and generates a separate n8n item for every single line item, combining it with the header data for a clean spreadsheet structure.

  7. Excel Conversion: The structured data is passed to the Convert to File n8n node, which renders all the items into a single, comprehensive Excel (XLS) file.

  8. Output: Finally, the Respond to Webhook n8n node sends the generated Excel file back as the HTTP response to the caller of the initial n8n trigger.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


  1. Import: Copy the provided JSON code and import it into your n8n instance as a new n8n workflow.

  2. Credentials: This n8n workflow relies on HTTP Basic Authentication for Nanonets.

Go to 'Credentials' in n8n.
Create a new credential using the 'HTTP Basic Auth' type.
Set the Username to your Nanonets API key.
Set the Password to a placeholder (e.g., 'X') as Nanonets only requires the API key in the username field for Basic Auth.

  1. Nanonets Setup: Before activating the n8n workflow, ensure you have created a Nanonets document extraction workflow (e.g., Invoice Processing).

  2. Endpoint Configuration: Update the URLs in both the 'HTTP Request' and 'HTTP Request2' n8n node instances to include your specific Nanonets Workflow ID. The ID is present in the URL path.

  3. Activation: Once configured, activate the n8n workflow and use the provided Webhook URL as your API endpoint for file submissions.

Node Details

Webhook (n8n trigger): The entry point of this n8n workflow. Configured to accept POST requests and respond once the entire process is complete. Key setting: Response Mode is Response Node.
HTTP Request (Nanonets Upload): Handles the initial file submission. Uses multipart-form-data and fetches the file binary data from the incoming webhook request.
Code (Document ID Extraction): A custom n8n node that parses the string response from the upload request, extracts the document_id, and passes it forward.
Wait: Pauses the n8n workflow for 15 seconds to ensure Nanonets completes its resource-intensive OCR task before attempting data retrieval.
HTTP Request2 (Data Retrieval): Uses the extracted documentId in its URL expression ({{ $json.documentId }}) to fetch the final, processed structured data from the Nanonets API.
Code1 (Data Structuring): The most complex n8n node. It transforms the nested Nanonets JSON response into a flat structure. It iterates through table cells to reconstruct line items, ensuring each line item gets its own item in the n8n workflow, ready for export.
Convert to File: An n8n node used to convert the structured JSON data items into a standard Excel (xls) binary format.
Respond to Webhook: The final n8n node that takes the binary Excel file generated by the previous step and sends it back to the initiating client.

Related n8n Workflows

Free

Nodes: 7 Nodes
Updated: December 26 2025
View all
Created by
Anurag
Anurag

Featured*