Automate EDI Order Parsing with Gmail & Google Sheets in n8n

This workflow automates processing EDI return and outbound orders received via Gmail. It parses complex EDI email messages, extracts detailed order data, and stores it smartly in Google Sheets, freeing hours of manual work and errors.
gmailTrigger
googleSheets
code
+5
Workflow Identifier: 1917
NODES in Use: Gmail Trigger, If, Gmail, Set, Code, Split Out, Merge, Google Sheets
Automate EDI parsing with Gmail and n8n

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

What this workflow does

This workflow helps read emails with “EDI” in the subject from Gmail. It takes the complex EDI message inside the email, breaks it down, and gets order details like order types, dates, parties, and line items. Then, it puts return orders and outbound orders in separate tabs in Google Sheets. This saves hours from manually copying data and avoids mistakes.


Who should use this workflow

Any business handling many EDI orders by email who wants to stop manual data entry for orders. It is good for people who want to easily check and organize order data. Users should have basic access to Gmail and Google Sheets and want automation for better accuracy and speed.


Tools and services used

  • Gmail API: To watch for new emails and get full email content.
  • n8n Workflow Automation: To build the automated process connecting Gmail, parsing, and Google Sheets.
  • Google Sheets API: To add parsed order lines to specific spreadsheet tabs.
  • JavaScript Code Nodes: To interpret EDI format messages inside emails and flatten data.

Inputs, processing steps, and outputs

Inputs

  • Emails in Gmail inbox with “EDI” in subject line.
  • Raw EDI message inside the email plain text body.

Processing steps

  • Check Gmail every minute for new emails matching “EDI” subject filter.
  • Download full email content including plain text body.
  • Clean and extract the EDI message text from email body.
  • Use JavaScript to parse EDI segments: UNB (envelope), UNH (header), BGM (document info), DTM (dates), NAD (parties), LIN and related nodes (order lines).
  • Flatten nested parsed data into rows combining document header with each order line.
  • Split orders by document type into Return Orders or Outbound Orders branch.
  • Append data rows to two separate Google Sheets tabs dedicated to returns and outbound orders.

Outputs

  • Return order details saved as rows in “Return Orders” Google Sheet tab.
  • Outbound order details saved as rows in “Outbound Orders” Google Sheet tab.

Beginner step-by-step: How to build this workflow in n8n

Importing and setup

  1. Inside the n8n editor, click the Download button on this page and save the workflow file to your computer.
  2. In n8n, use the “Import from File” function to upload the downloaded workflow file.
  3. Open the imported workflow. Add your Gmail and Google Sheets API credentials if not already done.
  4. Check each node needing setting, update email filters, spreadsheet IDs, sheet names, or other values to match your environment.
  5. If there is JavaScript code node for parsing, verify no changes needed unless your EDI format differs.

Testing and activation

  1. Run the workflow once manually with a test email containing an EDI message to confirm parsing and sheet updates work as expected.
  2. After successful test, toggle the workflow from inactive to active to let it run automatically.
  3. The workflow will now check Gmail every minute, parse incoming EDI emails, and update Google Sheets without manual work.

For setups running n8n on your own server, explore self-host n8n for full control.


Common issues and fixes

  • Emails not triggering workflow: Check Gmail API credentials are valid and polling is enabled.
  • EDI parsing errors: Confirm the raw email body text is captured correctly in the “Extract Body” node.
  • Google Sheets writing fails: Ensure Google Sheets node credentials and sheet/tab names are correct and access is allowed.

Customization ideas

  • Add filters by sender email to only process trusted partners.
  • Expand JavaScript parser code to extract more EDI fields like tax or discounts if needed.
  • Use different Google spreadsheets for return and outbound orders by adjusting spreadsheet IDs.
  • Add messaging platforms like Slack to notify teams when new orders arrive.
  • Set workflow to run only during work hours by adding a Cron node before Gmail trigger.

Summary of benefits and results

✓ Time saved from manual data entry—more than 3 hours daily.
✓ Fewer errors by automating EDI parsing and data logging.
✓ Clear separation of return and outbound orders in Google Sheets.
✓ Better order visibility and faster processing.
✓ Easy to test and activate inside n8n with basic setup steps.


Automate EDI parsing with Gmail and n8n

Visit through Desktop to Interact with the Workflow.

Frequently Asked Questions

The workflow uses a Gmail trigger node that checks emails every minute and filters those with “EDI” in the subject line.
The JavaScript parser code will need updating to handle the new EDI segments or structure.
Yes, by changing spreadsheet IDs in the Google Sheets nodes, it can write to different files.
Check the Google Sheets API credentials, sheet or tab names, and ensure the user has write permissions.

Promoted by BULDRR AI

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.