Projects

SharePoint Document Pipeline — Invoice Forms, Routing & Digital Signing

Automation
Python
Microsoft Graph
SharePoint
Docker

A containerised service that processes PDFs in SharePoint Online for a manufacturer's invoice workflow — appending a fillable company form, routing supplier invoices by rules kept in Excel with a visible digital signature, and keeping working folders tidy — replacing a Power Automate flow with tested, idempotent code.

Close-up of a tall, untidy stack of paper invoices and receipts

Challenge

Supplier invoices and other PDFs at a manufacturer move through SharePoint Online. Each document needs the company’s fillable form page attached before it goes further, and invoices for one approval queue were routed by a Power Automate flow — logic that lived outside version control, with no clear history of what failed and why. Files left behind in working folders went unnoticed, and whatever replaced the flow could never lose or silently alter a source document.

Solution

  • One containerised service, four jobs. A single asyncio Python service in Docker that talks to SharePoint only through Microsoft Graph, with app permissions limited to the one site it serves rather than the whole tenant.
  • Form attachment pipeline: PDFs dropped into a draft folder are checked and repaired in a local copy — the original is never modified — the company’s fillable form is appended with its fields still editable, and the result is published. XFA forms are rejected, a name clash archives the earlier output instead of overwriting it, and an already-signed PDF has its signature removed only in the working copy so the appended form stays editable.
  • Rule-based invoice routing that replaced the Power Automate flow: the text layer is matched against a supplier rule table maintained in Excel (30+ rules), requiring exactly one confirmed supplier by name and bank account; the invoice gets a status, a comment written into the form and a visible digital signature on the last page, with a structural PDF check after every step. It runs as an isolated module behind a feature flag with its own state, so a fault there never stops the main pipeline.
  • Safety by ordering: jobs are keyed on the file’s ID and version tag, so each version is processed once; the result is uploaded and recorded before the source is deleted — last, and only if it has not changed since. Any failure leaves the source exactly where it was.
  • Housekeeping and reminders: files left in the working folder for more than four hours are moved to a trash folder every hour, with the original uploader recorded; on weekday schedules a check emails — or messages in Teams — the full list of files waiting in watched folders, with recipients and rules edited in the web UI.
  • Operable by someone else: a small web UI with live job tables, error history and the trash view, health and readiness endpoints for the container, automated tests and a maintained documentation set (architecture, decisions, runbook).

Result

Running in production, the service took over invoice routing from Power Automate and handles form attachment, clean-up and reminders in the same place. Every rule and step is now in version control and covered by tests, failures are visible in one screen with the source document untouched, and working folders no longer collect forgotten files.