National Commerce Docs
n8n flows

Notify: New Draft PO Created

Emails brand users when a new draft purchase order is created, respecting their notification preferences.

When a new draft purchase order appears, this flow emails the relevant brand users. It honors each user's notification preferences and sends only once per PO.

At a glance

  • Status: Active
  • Trigger: Webhook (POST /webhook/4d6d3f71-ca60-4ef5-8a66-34651953b801), responds immediately.
  • Runs on: A call from Hourly: Create Draft POs when it creates a new draft PO.
  • Talks to: Supabase (Draft POs, Brands, userRoles, user_settings, Auth Admin API); Gmail.

How it works

  1. The webhook receives the draft PO id.
  2. The flow reads the draft PO record and checks notification_sent; if already sent, it stops.
  3. It sets notification_sent = true, then in parallel fetches the PO's account brand and its active users.
  4. Loop Over Users reads each user's preferences and checks send_notifications and inventory_management.draft_pos.
  5. For opted-in users it fetches the email through the Supabase Auth Admin API and sends a branded HTML notification via Gmail linking to the purchase-orders page.

Notes

  • Idempotent via the notification_sent flag: one email per PO.
  • Per-user opt-in gated on two preference flags.

On this page