{
  "id": "FUiT3OJ7phVWJ4FE",
  "name": "Send weekly AI-summarized Google Sheets reports via Gmail using OpenAI",
  "tags": [],
  "nodes": [
    {
      "id": "e4b864f9-60a5-47f8-a7c0-7b9cd0f7e963",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        32,
        208
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtDay": [
                1
              ],
              "triggerAtHour": 9
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "6d5cdac8-9819-4552-a5b7-4877d5e55165",
      "name": "Read Google Sheets Data",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        240,
        208
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "<__PLACEHOLDER_VALUE__Sheet name e.g. Sales Data__>"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "<__PLACEHOLDER_VALUE__Google Sheet ID with your data__>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "e37c6193-05d7-406c-8fc0-c13604c629a5",
      "name": "Aggregate Rows",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        464,
        208
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData",
        "destinationFieldName": "all_rows"
      },
      "typeVersion": 1
    },
    {
      "id": "fc737428-ddbc-4ec0-aca8-419b31cc8945",
      "name": "Generate Summary with AI",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        688,
        208
      ],
      "parameters": {
        "text": "=Here is data from a spreadsheet. Please write a brief weekly summary report highlighting key trends, totals, and any notable changes. Format it as a clean email body with bullet points.\n\nData:\n{{ JSON.stringify($json.all_rows) }}",
        "options": {
          "systemMessage": "You are a business analyst assistant. Write concise, professional weekly summary reports. Use bullet points and keep it under 300 words. Do not include greetings or sign-offs, just the report content."
        },
        "promptType": "define"
      },
      "typeVersion": 3
    },
    {
      "id": "405f5a97-32d5-4948-a0a9-3c82f551050c",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        688,
        384
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "3c7a8673-c627-47cc-af66-5cdb45f0b20c",
      "name": "Format Report",
      "type": "n8n-nodes-base.set",
      "position": [
        960,
        208
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "report_body",
              "type": "string",
              "value": "={{ $json.output }}"
            },
            {
              "id": "id-2",
              "name": "report_date",
              "type": "string",
              "value": "={{ $now.format('yyyy-MM-dd') }}"
            },
            {
              "id": "id-3",
              "name": "subject_line",
              "type": "string",
              "value": "=Weekly Report - {{ $now.format('yyyy-MM-dd') }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "f29d7344-f753-4cd8-b714-841fa1f269e6",
      "name": "Send Report Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1152,
        208
      ],
      "parameters": {
        "sendTo": "<__PLACEHOLDER_VALUE__Recipient email address__>",
        "message": "={{ $json.report_body }}",
        "options": {},
        "subject": "={{ $json.subject_line }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "9509f8bd-06f4-4b1e-b876-f6171e8b9a0a",
      "name": "Log Report Sent",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1344,
        208
      ],
      "parameters": {
        "columns": {
          "value": {
            "date": "={{ $json.report_date }}",
            "sent_at": "={{ $now.toISO() }}",
            "subject": "={{ $json.subject_line }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Report Log"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "<__PLACEHOLDER_VALUE__Google Sheet ID for report log__>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "b7d1527b-6d16-422d-87a5-49ff46547b79",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -592,
        32
      ],
      "parameters": {
        "color": 4,
        "width": 580,
        "height": 484,
        "content": "## How it works\n\nThis workflow runs automatically every Monday at 9am. It reads data from a Google Sheets spreadsheet, aggregates all the rows into a single payload, and sends it to OpenAI to generate a concise weekly summary report with key trends and highlights. The AI-generated report is formatted with a date-stamped subject line, emailed to your chosen recipient via Gmail, and logged to a separate spreadsheet so you have a record of every report sent.\n\n## Setup steps\n\n1. Adjust the Schedule Trigger if you want a different day or time\n2. Connect your Google Sheets account and set the spreadsheet ID and sheet name containing your data\n3. Connect your OpenAI credentials to the OpenAI Chat Model node\n4. Set the recipient email address in the Send Report Email node\n5. Connect your Gmail account for sending the report\n6. Create a \"Report Log\" sheet with columns: date, subject, sent_at\n7. Set the Report Log spreadsheet ID in the Log Report Sent node\n8. Activate the workflow"
      },
      "typeVersion": 1
    },
    {
      "id": "5d657543-990b-44c4-b7c7-dc015ee3af1e",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        48,
        96
      ],
      "parameters": {
        "color": 7,
        "width": 460,
        "height": 96,
        "content": "## Schedule & Read\nRuns every Monday at 9am, reads all rows from the data spreadsheet, and aggregates them."
      },
      "typeVersion": 1
    },
    {
      "id": "c04fe2b1-e2f3-4e15-93e3-f5053a3e2651",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        736,
        64
      ],
      "parameters": {
        "color": 7,
        "width": 500,
        "height": 112,
        "content": "## Summarize, Send & Log\nAI generates a summary report, emails it via Gmail, and logs the send to a separate spreadsheet."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "3d74d8e7-bfbe-4b27-8182-19f8875a534b",
  "connections": {
    "Format Report": {
      "main": [
        [
          {
            "node": "Send Report Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Rows": {
      "main": [
        [
          {
            "node": "Generate Summary with AI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Read Google Sheets Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Generate Summary with AI",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Send Report Email": {
      "main": [
        [
          {
            "node": "Log Report Sent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Google Sheets Data": {
      "main": [
        [
          {
            "node": "Aggregate Rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Summary with AI": {
      "main": [
        [
          {
            "node": "Format Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}