Integration2026
Connecting Shopify to invoicing and shipping
Staff were copying e-invoice keys from the ERP to the shipping platform by hand. I built an integration that checks each invoice and writes only valid keys to the Shopify order, with one shipment timeline across carriers. Built for three Brazilian D2C brands.
Credits Implementation assisted by AI coding agents





The panel that follows the integration: carrier and Shopify events

Shadow-mode report, 28 September 2026
Label decisions on real orders with writes disabled: one brand, three days
| Measure | Result |
|---|---|
| Orders evaluated | 37 |
| Ineligible orders proposed for a label | 0 |
| Eligible orders held back | 2 |
2,769 decisions logged: each order was re-checked every cycle until it settled. A period without Shopify access was excluded.
Problem
Every shipment needed an electronic tax invoice (NF-e, Brazil's e-invoice) issued in the ERP, Bling, before a label could be bought in the shipping platform, Frenet. Staff copied the invoice's access key from one system to the other by hand. Around that handoff:
- labels were sometimes created twice, or through the wrong shipping flow;
- there was no single view of each shipment across carriers, including a same-day courier connected through a logistics platform;
- bursts of ERP API calls hit its rate limit (HTTP 429), and a webhook that failed at the wrong moment could be lost.
What I built
- Webhooks stored before processing. Each ERP webhook is verified and saved before the service confirms receipt, and repeated deliveries are processed once.
- Invoice checks before Shopify. A worker re-reads each invoice from the ERP and only continues for the right type, an authorised status and a valid 44-digit key, then writes the key to the Shopify order with a concurrency check. The shipping platform reads it from there.
- One shipment timeline. Order stages and shipment statuses from the ERP, the shipping platform and the courier are normalised into one timeline for the agency's dashboard.
- Label decisions tested before automation. The label and fulfilment engine ran in shadow mode on real orders: it recorded what it would do, without creating labels or fulfilments, and I compared its decisions with what actually happened.
Proof
- First live invoice with no manual step: from the ERP to Shopify and on to the shipping platform. The worker processed it in 1.24 s on its first attempt (one recorded run); with the one-minute schedule, the key reached Shopify about 47 s after the ERP's webhook.
- Shadow evaluation, one brand, three days: with writes disabled, the engine evaluated 37 orders, re-checking each one as it changed (a period without Shopify access was excluded). Compared order by order with what happened in Shopify: 0 false positives (no ineligible order was proposed for a label) and 2 false negatives (eligible orders held back).
- Rate limits: after rescheduling one brand's ERP polling job and cutting calls per cycle from 26 to about 11, rate-limit errors for that job went from 119 in one 24-hour window to 0 in the next (96 cycles, live traffic).
- Tests in CI, 2 October 2026: 1,123 automated tests and 1,323 database assertions passing; every push also runs formatting, linting, type checks and secret scanning.

Where the team sees it
The integration feeds the logistics panel inside the agency dashboard: late, stalled and in-transit orders, the ones that need action, one timeline per order and the exceptions to resolve. The screens below run the panel's own code with synthetic orders in an isolated demo, with no production endpoint called; the live panel holds customer data.

The order timeline at the top of this page comes from the same panel: Shopify and carrier events in one list, newest first; ERP events join the same list.
Tech details
How it's built
Architecture
- Supabase Postgres with a private schema and an RPC-only API: no direct table access, and every operation goes through reviewed database functions.
- 21 Deno Edge Functions, pg_cron, pgTAP and GitHub Actions.
- The worker runs every minute and claims events with
FOR UPDATE SKIP LOCKED; events left in progress for five minutes go back to the queue. Retries use capped exponential backoff with jitter, and ERP calls are spaced at least 500 ms apart. - Shopify writes go to an order metafield with read → compare → write, so a concurrent change is detected instead of overwritten. GraphQL
userErrorsinside an HTTP 200 count as failures. - Invoices that fail the checks are marked ignored, failed or in conflict, and their keys never reach Shopify.
- The shadow run logged 2,769 decisions over the three days, because each order was re-evaluated every cycle until it settled.
Decisions that mattered
- Store first, then acknowledge. An earlier prototype answered "success" even when its insert failed, which can lose an event silently.
- Check the invoice against the ERP before updating Shopify. During rollout, this stopped a still-pending invoice from being written to a live order.
- New invoices only at first. Historical orders stayed manual, which limited the impact of rollout errors and kept rollback simple.
- Evaluate label actions before enabling writes, and treat "held back" as the safe way to fail.
What this means for your store
This project used Brazilian ERP and shipping providers (Bling, Frenet and a logistics platform). For another provider, I would first check its API and test the workflow in a sandbox, then adapt the event handling, retries and validation.
or e-mail contato@rafaelshopify.dev

