n8n Workflow
Advanced

Process API Data: Google Sheets, CSV & Email Attachment Workflow

Automate fetching data from a REST API, appending it to Google Sheets, converting it to CSV, and emailing it as a JSON attachment. Ideal for data integration and reporting.

Overview

Automates fetching data from an API, transforming it, and distributing it to Google Sheets, as a CSV file, and as an email attachment for reporting and data pipelines.

🗂️ Description & Use Case

This workflow demonstrates a comprehensive data processing pipeline. It fetches data from an external API, formats it, and then routes it through multiple paths to showcase different data handling capabilities, including writing to Google Sheets, creating a CSV file, and emailing a JSON file as an attachment.

⚙️ How It Works:

  1. Fetch User Data: The workflow begins with an HTTP Request node that calls the randomuser.me API to retrieve random user data in JSON format.

  2. Format Data: A Set node simplifies the incoming JSON, extracting only the user's full name and country. This step ensures the data is clean and ready for the next stages.

  3. Distribute Data (3 Paths):

    • Path A: Direct to Google Sheets: The formatted data is immediately sent to a Google Sheets node, which appends it as a new row. This is perfect for creating a running log or simple database from an API source.

    • Path B: Convert to CSV: In parallel, the data is passed to a Spreadsheet File node, which converts the JSON data into a CSV file format, useful for local backups or sharing.

    • Path C: Email as JSON & Re-import: This path demonstrates an advanced data flow:

      1. The data is converted into a binary JSON file named randomusers.json.
      2. A Gmail node sends an email with this JSON file as an attachment.
      3. Finally, the workflow simulates processing an incoming email by extracting the attachment from the sent item and appending its contents to another Google Sheet. This showcases a full-circle data handling process.

✅ Real-World Use Cases:

  • Automated Reporting: Schedule daily API data pulls and save the results directly into a Google Sheet for team analysis without manual intervention.
  • Data Backup & Archiving: Automatically back up important data from an API into multiple formats (e.g., Google Sheets for accessibility, CSV for long-term storage).
  • ETL Pipelines: Use this structure as a basic ETL (Extract, Transform, Load) process to move and reshape data between different web services and file formats.
  • Automated Data Delivery: Send periodic data exports to clients or stakeholders as email attachments in their preferred format.

Instructions

Basic steps

  1. Download workflow JSON
  2. Import into n8n
  3. Configure node parameters as needed
  4. Test and enable the workflow

💡 Tips

After importing, verify all connectors and credentials match your environment.

Preview

Workflow Visualization

14 nodes
100%
HTTP RequesthttpRequestGoogle SheetsgoogleSheetsSetsetSpreadsheet FilespreadsheetFileSpreadsheet File1spreadsheetFileWrite Binary FilewriteBinaryFileMove Binary Data1moveBinaryDataGmail1gmailGoogle Sheets2googleSheetsMove Binary Data2moveBinaryDataNotestickyNoteNote1stickyNoteNote2stickyNoteNote3stickyNote

Nodes

1

HTTP Request

httpRequest

v2
2

Google Sheets

googleSheets

v1
3

Set

set

v1
4

Spreadsheet File

spreadsheetFile

v1
5

Spreadsheet File1

spreadsheetFile

v1
6

Write Binary File

writeBinaryFile

v1
7

Move Binary Data1

moveBinaryData

v1
8

Gmail1

gmail

v1
9

Google Sheets2

googleSheets

v1
10

Move Binary Data2

moveBinaryData

v1
11

Note

stickyNote

v1
12

Note1

stickyNote

v1
13

Note2

stickyNote

v1
14

Note3

stickyNote

v1

Statistics

Total nodes:14
Disabled nodes:0
Node types:8
Connections:8
View full JSON structure
{
  "nodes": [
    {
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        560,
        700
      ],
      "parameters": {
        "url": "https://randomuser.me/api/",
        "options": {}
      },
      "typeVersion": 2
    },
    {
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        960,
        560
      ],
      "parameters": {
        "range": "A:C",
        "options": {
          "usePathForKeyRow": true
        },
        "sheetId": "qwertz",
        "operation": "append",
        "authentication": "oAuth2"
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "2",
          "name": "google_sheets_oauth"
        }
      },
      "typeVersion": 1
    },
    {
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "position": [
        760,
        700
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "name",
              "value": "={{$json[\"results\"][0][\"name\"][\"first\"]}} {{$json[\"results\"][0][\"name\"][\"last\"]}}"
            },
            {
              "name": "country",
              "value": "={{$json[\"results\"][0][\"location\"][\"country\"]}}"
            }
          ]
        },
        "options": {},
        "keepOnlySet": true
      },
      "typeVersion": 1
    },
    {
      "name": "Spreadsheet File",
      "type": "n8n-nodes-base.spreadsheetFile",
      "position": [
        960,
        840
      ],
      "parameters": {
        "options": {
          "fileName": "users_spreadsheet"
        },
        "operation": "toFile",
        "fileFormat": "csv"
      },
      "typeVersion": 1
    },
    {
      "name": "Spreadsheet File1",
      "type": "n8n-nodes-base.spreadsheetFile",
      "position": [
        960,
        1200
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "name": "Write Binary File",
      "type": "n8n-nodes-base.writeBinaryFile",
      "position": [
        1360,
        1200
      ],
      "parameters": {
        "fileName": "randomusers.json"
      },
      "typeVersion": 1
    },
    {
      "name": "Move Binary Data1",
      "type": "n8n-nodes-base.moveBinaryData",
      "position": [
        1160,
        1200
      ],
      "parameters": {
        "mode": "jsonToBinary",
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "name": "Gmail1",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1360,
        1420
      ],
      "parameters": {
        "message": "Hello, attached is a JSON file with random user information.",
        "subject": "JSON file with users",
        "additionalFields": {
          "attachmentsUi": {
            "attachmentsBinary": [
              {
                "property": "data"
              }
            ]
          }
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "16",
          "name": "gmail"
        }
      },
      "typeVersion": 1
    },
    {
      "name": "Google Sheets2",
      "type": "n8n-nodes-base.googleSheets",
      "notes": "Append data to sheet",
      "position": [
        1760,
        1420
      ],
      "parameters": {
        "range": "A:C",
        "options": {
          "usePathForKeyRow": true
        },
        "sheetId": "qwertz",
        "operation": "append",
        "authentication": "oAuth2"
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "2",
          "name": "google_sheets_oauth"
        }
      },
      "notesInFlow": true,
      "typeVersion": 1
    },
    {
      "name": "Move Binary Data2",
      "type": "n8n-nodes-base.moveBinaryData",
      "position": [
        1560,
        1420
      ],
      "parameters": {
        "options": {},
        "sourceKey": "attachment_0"
      },
      "typeVersion": 1
    },
    {
      "name": "Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1200,
        560
      ],
      "parameters": {
        "width": 320,
        "height": 80,
        "content": "## JSON > Google Sheets"
      },
      "typeVersion": 1
    },
    {
      "name": "Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1200,
        860
      ],
      "parameters": {
        "width": 320,
        "height": 80,
        "content": "## JSON > CSV"
      },
      "typeVersion": 1
    },
    {
      "name": "Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        580,
        1220
      ],
      "parameters": {
        "width": 320,
        "height": 80,
        "content": "## CSV > JSON file"
      },
      "typeVersion": 1
    },
    {
      "name": "Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        980,
        1460
      ],
      "parameters": {
        "width": 320,
        "height": 80,
        "content": "## JSON file > Google Sheets"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Set": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          },
          {
            "node": "Spreadsheet File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail1": {
      "main": [
        [
          {
            "node": "Move Binary Data2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Spreadsheet File": {
      "main": [
        [
          {
            "node": "Spreadsheet File1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Move Binary Data1": {
      "main": [
        [
          {
            "node": "Write Binary File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Move Binary Data2": {
      "main": [
        [
          {
            "node": "Google Sheets2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Spreadsheet File1": {
      "main": [
        [
          {
            "node": "Move Binary Data1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write Binary File": {
      "main": [
        [
          {
            "node": "Gmail1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Actions

Share
Categories:
Tags:
setgmailhttprequestgooglesheetsspreadsheetfilewritebinaryfilemovebinarydatastickynote

Technical Specs

Complexity:
Advanced
Node Count:
14 nodes
Published:11 months ago
Updated:10 days ago

Compatibility

Platform:
N8N Cloud & Self-hosted
Min Version:
N8N v1.0.0+
Supports cloud and self-hosted deployment

License

This workflow template follows MIT license, you can freely use, modify and distribute.

Please comply with relevant third-party service terms when using.

Related Workflows