<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Eeman Asghar</title>
    <description>The latest articles on DEV Community by Eeman Asghar (@eeman_asghar_ad5be19be8b7).</description>
    <link>https://dev.to/eeman_asghar_ad5be19be8b7</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3437713%2Fae6d3d22-2bbe-4abd-a7e0-0b127865883d.png</url>
      <title>DEV Community: Eeman Asghar</title>
      <link>https://dev.to/eeman_asghar_ad5be19be8b7</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/eeman_asghar_ad5be19be8b7"/>
    <language>en</language>
    <item>
      <title>Automating Procure-to-Pay with Precision: How I Engineered an End-to-End Invoice Processing System in n8n</title>
      <dc:creator>Eeman Asghar</dc:creator>
      <pubDate>Fri, 15 Aug 2025 19:23:08 +0000</pubDate>
      <link>https://dev.to/eeman_asghar_ad5be19be8b7/automating-procure-to-pay-with-precision-how-i-engineered-an-end-to-end-invoice-processing-system-399f</link>
      <guid>https://dev.to/eeman_asghar_ad5be19be8b7/automating-procure-to-pay-with-precision-how-i-engineered-an-end-to-end-invoice-processing-system-399f</guid>
      <description>&lt;p&gt;In enterprise operations, few workflows are as ripe for automation, and yet as fragile to implement as Procure-to-Pay (P2P). Mismatched invoices, missing approvals, buried purchase orders, and manual GRN reconciliation can grind any finance team to a halt. I built a production-grade P2P automation system using &lt;strong&gt;n8n&lt;/strong&gt; to replace this fragmented mess with structured, auditable, and intelligent workflows.&lt;/p&gt;

&lt;p&gt;This is not a prototype. It’s a complete automation backbone capable of ingesting vendor invoices from email, parsing and validating every detail, matching them against procurement records, and routing approvals or exceptions, all while maintaining a robust audit trail.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Automate This?
&lt;/h2&gt;

&lt;p&gt;The traditional P2P process is loaded with friction:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Invoices arrive in unstructured formats, often scanned or image-based.&lt;/li&gt;
&lt;li&gt;Manual extraction leads to errors and delays.&lt;/li&gt;
&lt;li&gt;Validation steps — PO matching, GRN checks, approval routing — require constant coordination.&lt;/li&gt;
&lt;li&gt;Finance teams spend hours triaging mismatches and searching shared drives.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My goal was to make this entire process &lt;strong&gt;deterministic, traceable, and modular&lt;/strong&gt;, so each part could evolve independently without breaking the whole system.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;The architecture is composed of &lt;strong&gt;six connected n8n workflows&lt;/strong&gt;, orchestrated through well-defined triggers, subflows, and handoffs:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Gmail Trigger&lt;/strong&gt; – Captures incoming invoice emails and attachments in real-time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PDF Validation&lt;/strong&gt; – Ensures only legitimate PDF files are processed (rejects mislabeled or corrupted formats).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PDF-to-Image Conversion&lt;/strong&gt; – Uses PDF.co to normalize documents into image form for parsing consistency.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;OCR Pipeline&lt;/strong&gt; – Applies AI-driven OCR (LLM-based) to extract raw text from invoice images, regardless of layout.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Entity Extraction&lt;/strong&gt; – Uses OpenAI to structure the output: PO number, GRN, vendor, amount, currency.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reconciliation Engine&lt;/strong&gt; – Compares extracted data against SharePoint-based PO/GRN logs and flags mismatches.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Approval Subflows&lt;/strong&gt; – Routes approval requests via Gmail for PO and GRN when required, with outcomes logged back into Excel 365.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each node is crafted for resilience, and every junction point includes validation guards, error exits, and structured logging.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Engineering Decisions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Modular Subflows
&lt;/h3&gt;

&lt;p&gt;Instead of building a monolithic pipeline, I split the system into distinct workflows: one each for invoice parsing, PO approval, GRN validation, and audit logging. Subflows are triggered via &lt;code&gt;Execute Workflow&lt;/code&gt; nodes with dynamic input mappings, keeping everything loosely coupled.&lt;/p&gt;

&lt;h3&gt;
  
  
  File Validation Before OCR
&lt;/h3&gt;

&lt;p&gt;Early on, I ran into MIME-type mismatches: files with &lt;code&gt;.pdf&lt;/code&gt; extensions that weren’t actually PDFs. I added MIME-type and extension checks to block malformed inputs early, saving compute and preventing downstream errors.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if ($binary.data.mimeType !== 'application/pdf') {
  throw new Error('Invalid file type: Must be a PDF');
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  PDF.co Limitations
&lt;/h3&gt;

&lt;p&gt;PDF.co’s API only accepts hosted files. To handle this, I built a two-stage upload + convert process. Once I had the temporary URL, I passed it into the converter. The result was a structured array of image links, which I flattened using &lt;code&gt;Set&lt;/code&gt; and &lt;code&gt;Split&lt;/code&gt; nodes to emit one item per page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "url": "https://secure-temp-file.pdf",
  "pages": "1-ALL",
  "outputFormat": "jpg"
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  AI Parsing with Guardrails
&lt;/h3&gt;

&lt;p&gt;OCR is handled by an OpenAI-powered LangChain node chain. I injected formatting instructions to ensure output is returned as structured JSON. If the response is malformed or empty, the system halts with an actionable error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "po_number": "PO-12345",
  "vendor": "Acme Supplies",
  "amount": 4520.75,
  "currency": "USD",
  "grn": "GRN-67890"
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Matching Logic with Excel 365
&lt;/h3&gt;

&lt;p&gt;I used Microsoft Excel 365 on SharePoint to simulate an ERP-like registry. Matching logic compares AI outputs against actual records, and flags mismatches for review. This offered just enough structure for automation without needing a full-blown database.&lt;/p&gt;

&lt;h3&gt;
  
  
  Audit Trail and Compliance
&lt;/h3&gt;

&lt;p&gt;Each approval or exception is logged with a timestamp in Excel. This provides a transparent audit trail, something manual processes rarely achieve.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measurable Business Value
&lt;/h2&gt;

&lt;p&gt;Once integrated into daily operations, this workflow can save &lt;strong&gt;3–5 hours per week per finance team member&lt;/strong&gt;, depending on invoice volume. It reduces human touchpoints, flags mismatches instantly, and ensures that only compliant invoices get through.&lt;/p&gt;

&lt;p&gt;Just as importantly, it gives operations leaders peace of mind: every invoice is processed the same way, every time, with full visibility and accountability.&lt;/p&gt;

&lt;p&gt;This project reinforced something I believe strongly: &lt;strong&gt;real-world automation isn’t about flashy AI wrappers&lt;/strong&gt;. It’s about invisible reliability, quietly moving data across systems with precision, handling the edge cases, and giving humans time back where it matters.&lt;/p&gt;

&lt;p&gt;I didn’t just automate P2P. I redesigned how it could work better, and made that design real, one node at a time.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>api</category>
      <category>automation</category>
      <category>architecture</category>
    </item>
  </channel>
</rss>
