Trouble mapping dynamic URL in "Edit Fields" node — scraping emails from Google Maps workflow

Hey everyone :wave:

I’m building an AI agent in n8n that scrapes emails from Google Maps results, classifies them, and saves the data to Google Sheets. Here’s the current flow:

  1. Telegram Trigger: The user sends a keyword via Telegram, e.g. fencing+suppliers+melbourne
  2. HTTP Request: Fetches the URL https://www.google.com/maps/search/{keyword}
  3. Code Node: Scrapes business URLs from the HTML response
  4. Filter: Removes irrelevant URLs
  5. Remove Duplicates
  6. HTTP Request (per URL): Visits each website
  7. Code Node: Scrapes emails from the web page
  8. Aggregate email arrays
  9. Split out each email
  10. Remove duplicate emails
  11. Filter irrelevant emails
  12. Edit Fields: I group the email and URL to send to the AI agent (image below)
  • The email field maps fine (from the “Filter irrelevant emails” node)
  • The URL field is the issue — I’m trying to map it from the “Remove duplicate URL” node, but that node contains a list of 20+ URLs
  • So n8n throws this error:

Multiple matching items for expression [item 0]
An expression here won’t work because it uses .item and n8n can’t figure out the matching item. (There are multiple possible matches)

Try using .first(), .last() or .all()[index] instead of .item or reference a different node.

  1. AI Agent classifies:
  • Email
  • URL
  • Company category
  • Company name
  • Scrape date
  1. Edit Fields: I map the AI output
  2. Google Sheets: Final structured data is stored

My question:
How can I correctly map the matching URL to each email in the “Edit Fields” node? The emails are split already, but the URLs are still in a list — how can I ensure the correct URL matches the right email during mapping?

If anyone wants to see the inside of any specific node (since I can’t include all screenshots in this post), just let me know which one you’re interested in and I’ll share it.

Thanks in advance :pray:

Information on your n8n setup

  • n8n version:1.86.1
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

What would be the matching criterion? I.e. how would you know which of 22 urls to attach to each of 14 emails?

You probably need to Merge urls and emails at an earlier stage while there is still a 1:1 relation between each url and email (or list of emails) deriving from it.

I wouldn’t rely on partial url match as it is, in general, not an unusual situation where website and email for the same business are hosted on different domains.

If your question is resolved by the above suggestion, please mark this post as a :white_check_mark: Solution.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.