{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "ab1b7d2d-7eac-45eb-9e0a-36f14c56df14",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -592,
        -944
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "be31a0f1-8b41-48ea-b80b-cf3de29df733",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1088,
        -1536
      ],
      "parameters": {
        "width": 400,
        "height": 1056,
        "content": "\n## \u2699\ufe0f Setup Instructions\n\n### 1\ufe0f\u20e3 Connect Gmail\n1. In **n8n \u2192 Credentials \u2192 New \u2192 Gmail OAuth2**  \n2. Log in with your Gmail account & approve access  \n3. Attach this credential to the **Get new messages** node in the workflow  \n\n---\n\n### 2\ufe0f\u20e3 Connect Google Sheets\n1. Copy this [Google Sheet template](https://docs.google.com/spreadsheets/d/1t5VXtbo9g7SvGDPmeZok4HG1K-WI1PS0DNBylzmhVwg/edit?usp=drivesdk) into your own Drive  \n2. In **n8n \u2192 Credentials \u2192 New \u2192 Google Sheets (OAuth2)** \u2192 log in with your Google account & save  \n3. In the workflow, select your Spreadsheet ID and Worksheet (Sheet1 by default) in the **Google Sheets nodes**  \n\n---\n\n## \ud83d\udcec Contact\nNeed help customizing this (e.g., filter by sender, auto-reply, or Slack notifications)?  \n\n\ud83d\udce7 **robert@ynteractive.com**  \n\ud83d\udd17 **[Robert Breen](https://www.linkedin.com/in/robert-breen-29429625/)**  \n\ud83c\udf10 **[ynteractive.com](https://ynteractive.com)**\n"
      },
      "typeVersion": 1
    },
    {
      "id": "1d6e32b0-92fe-4473-a207-e895e66b79e2",
      "name": "Sticky Note52",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -480,
        -1296
      ],
      "parameters": {
        "color": 3,
        "width": 224,
        "height": 336,
        "content": "### 1\ufe0f\u20e3 Connect Gmail\n1. In **n8n \u2192 Credentials \u2192 New \u2192 Gmail OAuth2**  \n2. Log in with your Gmail account & approve access  \n3. Attach this credential to the **Get new messages** node in the workflow  "
      },
      "typeVersion": 1
    },
    {
      "id": "4f9c9dd4-6a32-4175-bde4-59224486c5ac",
      "name": "Sticky Note50",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -640,
        -1536
      ],
      "parameters": {
        "color": 7,
        "width": 1392,
        "height": 1056,
        "content": "# \ud83d\udccb Track Gmail Messages in Google Sheets with Automated Logging\n\nThis workflow automatically **fetches new Gmail messages since the last run** and appends them into a **Google Sheet** with their ID, snippet, and timestamp.  \nUse it to keep an ongoing log of emails, create lightweight CRMs, or power downstream automations.\n\n---"
      },
      "typeVersion": 1
    },
    {
      "id": "0ba209c5-f532-4a98-a60d-2c3867b7890f",
      "name": "Sticky Note54",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        432,
        -992
      ],
      "parameters": {
        "color": 3,
        "width": 288,
        "height": 368,
        "content": "\n### 2\ufe0f\u20e3 Connect Google Sheets\n1. Copy this [Google Sheet template](https://docs.google.com/spreadsheets/d/1t5VXtbo9g7SvGDPmeZok4HG1K-WI1PS0DNBylzmhVwg/edit?usp=drivesdk) into your own Drive  \n2. In **n8n \u2192 Credentials \u2192 New \u2192 Google Sheets (OAuth2)** \u2192 log in with your Google account & save  \n3. In the workflow, select your Spreadsheet ID and Worksheet (Sheet1 by default) in the **Google Sheets nodes**  \n"
      },
      "typeVersion": 1
    },
    {
      "id": "89e5ccfd-b798-427d-a3fb-e1c71e408076",
      "name": "Add Emails to Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        544,
        -752
      ],
      "parameters": {
        "columns": {
          "value": {
            "id": "={{ $json.id }}",
            "snippet": "={{ $('Get Current Emails').item.json.snippet }}",
            "datetime": "={{ $('Get Todays Date').item.json.date }}"
          },
          "schema": [
            {
              "id": "id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "id",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "snippet",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "snippet",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "datetime",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "datetime",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1t5VXtbo9g7SvGDPmeZok4HG1K-WI1PS0DNBylzmhVwg/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1t5VXtbo9g7SvGDPmeZok4HG1K-WI1PS0DNBylzmhVwg",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1t5VXtbo9g7SvGDPmeZok4HG1K-WI1PS0DNBylzmhVwg/edit?usp=drivesdk",
          "cachedResultName": "Emails"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "7fed2ca3-3b0e-4cd9-89e1-364e21e1e67d",
      "name": "Get Todays Date",
      "type": "n8n-nodes-base.code",
      "position": [
        -176,
        -848
      ],
      "parameters": {
        "jsCode": "// n8n Code node (JavaScript) - ISO UTC format\nconst now = new Date();\n\n// Output as ISO string (e.g., 2025-08-25T21:07:22Z)\nconst formatted = now.toISOString().replace(/\\.\\d{3}Z$/, 'Z');\n\nreturn [{ date: formatted }];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "57a1dc13-b00a-496c-b121-1b56444fc878",
      "name": "Get Current Emails",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -416,
        -1104
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1t5VXtbo9g7SvGDPmeZok4HG1K-WI1PS0DNBylzmhVwg/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1t5VXtbo9g7SvGDPmeZok4HG1K-WI1PS0DNBylzmhVwg",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1t5VXtbo9g7SvGDPmeZok4HG1K-WI1PS0DNBylzmhVwg/edit?usp=drivesdk",
          "cachedResultName": "Emails"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "7a474f8f-7ca2-4c91-aff3-b69ecce19677",
      "name": "Get Max Date",
      "type": "n8n-nodes-base.summarize",
      "position": [
        -96,
        -1216
      ],
      "parameters": {
        "options": {},
        "fieldsToSummarize": {
          "values": [
            {
              "field": "datetime",
              "aggregation": "max"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "0a1d33af-d580-4753-af4c-aba65f7c623f",
      "name": "Combine",
      "type": "n8n-nodes-base.merge",
      "position": [
        272,
        -1264
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineAll"
      },
      "typeVersion": 3.2
    },
    {
      "id": "2bc48807-0c03-4cac-ad18-60b99e7dc6aa",
      "name": "Get new messages",
      "type": "n8n-nodes-base.gmail",
      "position": [
        272,
        -976
      ],
      "parameters": {
        "simple": false,
        "filters": {
          "receivedAfter": "={{ $json.max_datetime }}"
        },
        "options": {},
        "operation": "getAll",
        "returnAll": true
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    }
  ],
  "connections": {
    "Combine": {
      "main": [
        [
          {
            "node": "Get new messages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Max Date": {
      "main": [
        [
          {
            "node": "Combine",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Todays Date": {
      "main": [
        [
          {
            "node": "Combine",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Get new messages": {
      "main": [
        [
          {
            "node": "Add Emails to Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Current Emails": {
      "main": [
        [
          {
            "node": "Get Max Date",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Emails to Sheets": {
      "main": [
        []
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Get Todays Date",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get Current Emails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}