n8n

How to Automate Gmail EDI to Google Sheets Orders?

Turn EDI purchase orders that arrive by email into clean rows in Google Sheets. Great for operations and warehouse teams that need fast order intake without an EDI gateway. It watches Gmail, reads messages that mention EDI, and writes both order headers and line items into the right sheets.

The flow starts with a Gmail trigger that checks the subject for EDI. It pulls the email body, cleans the text, and runs a JavaScript parser that extracts header fields, partner details, dates, and each line item from EDIFACT segments. Data is flattened so each row represents one order line and is merged with order level fields. A decision step sends records to Return Orders or Outbound Orders and appends rows to specific Google Sheets tabs.

Setup needs Gmail and Google Sheets credentials in n8n. Send the sample EDI from the note to your inbox to test parsing and mapping. Expect big time savings on data entry, fewer copy paste errors, and quicker handoffs to picking and packing. Teams that receive orders by email can scale volume without adding headcount.

What are the key features?

  • Gmail trigger checks new emails and filters subjects that include EDI
  • Get Email node pulls the full message by ID for reliable parsing
  • Extract Body step normalizes line breaks and removes extra quotes
  • Custom code parses EDIFACT segments like BGM, DTM, NAD, LIN, QTY, and PRI
  • Flattening logic turns nested order lines into one row per line item
  • Merge step attaches order level fields to each line item
  • If condition routes records by documentType to returns or outbound flows
  • Google Sheets nodes append rows to dedicated tabs in the same file
  • Split Out processes each line item independently for stable writes

What are the benefits?

  • Reduce manual data entry from 60 minutes to 5 minutes per order batch
  • Automate up to 90% of repetitive copy paste work
  • Improve data accuracy by 95% by parsing structured EDI fields
  • Handle up to 10 times more orders with the same team
  • Connect Gmail and Google Sheets seamlessly for live tracking

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with Gmail and Google Sheets. See the Tools Required section above for links to create accounts with these services.
  3. Open the Gmail Trigger node and in the Credential to connect with field click Create new credential. Follow the on screen steps to authorize your Gmail account.
  4. Open the Gmail Get Email node and select the same Gmail credential. Leave Operation as get and keep the Message ID expression intact.
  5. Open each Google Sheets node and click Create new credential if needed. You can use OAuth to sign in with your Google account. If you use a service account, share the target spreadsheet with the service account email.
  6. In both Google Sheets nodes, choose the spreadsheet by name or paste the file ID. Pick the correct tab for Return Orders and Outbound Orders.
  7. Check the If node that filters the subject. Make sure it looks for the word EDI so only relevant emails are processed.
  8. Review the Set node named Extract Body. Keep the expression that fixes line breaks so the parser reads the message correctly.
  9. Send a test email to your Gmail with subject EDI Test and paste the sample EDI payload into the body as plain text. Trigger a manual execution to validate.
  10. Open Executions, inspect the Parse EDI Message output, and confirm you see order headers and line items. If parsing fails, ensure the email body is plain text and not HTML.
  11. Verify rows appear in your Google Sheets tabs. Check column headers and adjust mapping if your sheet uses different field names.
  12. If no rows route to a tab, review the Order Type condition and confirm the documentType values match your data. Add a default branch if needed.
  13. Monitor quotas. If Gmail rate limits, increase the poll interval on the trigger or narrow the subject filter to reduce volume.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

Gmail

Sign up

No cost: Personal Gmail (Gmail API has no usage-based pricing; quotas apply)

Google Sheets

Sign up

Free: $0 (Google Sheets API usage has no additional cost; quota limits apply)

Credits:
Samir Saci. YouTube video

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.