Automated Lead Capture and Synchronization from Apify to Google Sheets - n8n Workflow

Use this powerful n8n workflow template to automate lead scraping via Apify, clean the extracted data using an n8n code node, and instantly update Google Sheets. This robust n8n automation template ensures clean, reliable data delivery.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Sales and Marketing Teams: Users needing a continuous feed of clean business leads without manual intervention.
Growth Hackers: Individuals leveraging web scraping tools like Apify and requiring reliable data synchronization.
n8n Automation Engineers: Users seeking efficient n8n templates for integrating scraping APIs with core business applications like Google Sheets.
Data Managers: Those who need to ensure scraped data, especially phone numbers and emails, are consistently clean before storage.

Overview

Managing lead generation often involves running external scraping tools and manually ensuring data quality before entering it into a CRM or database. This is slow and prone to error. This sophisticated n8n workflow solves this by creating a hands-free integration pipeline.

It utilizes a robust n8n trigger to initiate the process, automatically pulls fresh data from your specified Apify task, and crucially, cleans the phone and email fields using a custom n8n code node. By automating this data standardization, the n8n workflow guarantees that only high-quality, formatted leads are appended to your Google Sheet, ready for immediate use. This n8n template is essential for anyone looking to professionalize their data collection process.

How it Works

The entire process is managed efficiently within a single n8n workflow structure:


  1. Start: The n8n workflow is initiated via the Manual Trigger (which can easily be swapped for a Schedule or Webhook n8n trigger for production use).

  2. Credential Setup: The Variables n8n node securely defines the necessary API keys (APIFYTOKEN and APIFYTASKID) needed for the subsequent steps.

  3. Scraping Execution: The Run Apify Scraper n8n node, configured as an HTTP Request, calls the Apify API endpoint (run-sync-get-dataset-items). This executes the defined scraping task and fetches the results, splitting the output into individual items for further processing.

  4. Data Cleaning: The custom Clean Data n8n code node iterates over every scraped item. It uses JavaScript to sanitize the data, specifically removing all non-digit characters (except '+') from the phone field and converting the email field to lowercase and trimming whitespace.

  5. Data Export: The final step uses the Export to Google Sheets n8n node. This node connects to the specified spreadsheet (defined by YOURGOOGLESHEETID) and appends the cleaned data—mapping company name, phone, and Address to the corresponding sheet columns. This completes the automated n8n workflow execution.

Installation Guide

To deploy and use this powerful n8n workflow template, follow these steps:


  1. Import: Copy the entire JSON code and import it into your n8n instance using the 'New' > 'Import from JSON' function.

  2. Credentials: Set up the required n8n credentials for the following services:

Google Sheets: Authenticate your Google Sheets account to allow n8n to write data.

  1. Configure Variables: Navigate to the Variables n8n node and update the placeholder values:

APIFYTOKEN: Replace YOURAPIFYAPITOKEN with your actual Apify API token.
APIFYTASKID: Replace YOURAPIFYTASK_ID with the ID of the Apify Actor Task you wish to run.

  1. Configure Google Sheets:

Select the correct Credential.
* In the Export to Google Sheets n8n node, select the correct Document ID and Sheet Name. Ensure the Sheet has the required headers: company name, phone, and Address.

  1. Activation: Save and activate the n8n workflow. Use the Manual Trigger to test the full pipeline.

Node Details

This n8n workflow utilizes several key n8n node components:

Manual Trigger (n8n trigger): The starting point for the workflow. It allows for quick, manual execution of the data pipeline for testing and one-off runs.
Variables (Set n8n node): A utility node used to set environment-like variables (APIFYTOKEN, APIFYTASK_ID) centrally, simplifying credential management across the n8n workflow.
Run Apify Scraper (HTTP Request n8n node): Essential for fetching external data. It dynamically constructs the Apify API URL using the defined variables to synchronize and retrieve dataset items. Crucially, it splits the JSON array response into individual n8n items for granular processing.
Clean Data (Code n8n node): This highly effective n8n node performs pre-processing logic. It executes custom JavaScript to ensure data integrity by normalizing phone numbers and standardizing email format.


  • Export to Google Sheets (Google Sheets n8n node): The final destination n8n node. It uses the append operation to seamlessly add the cleaned lead data to the target Google spreadsheet, mapping inputs like ={{ $json.phone }} to the correct column headers.

Related n8n Workflows

Free

Nodes: 6 Nodes
Updated: December 26 2025
View all
Created by

I love building smart, efficient automations with n8n that help businesses save time and scale effortlessly. Turning complex workflows into simple solutions is where I have the most fun

Featured*