{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "2bb6ff51-68a4-469f-be3a-73ff1886f071",
      "name": "Schedule Workflow",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1824,
        1824
      ],
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "92feb1f7-fc98-43a5-98ed-35298b341043",
      "name": "Get Data",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -1536,
        1712
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/19aUQYZq02qHsCelO4eeV4sx_MTJJupC5qe0gDLQBtRA/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "19aUQYZq02qHsCelO4eeV4sx_MTJJupC5qe0gDLQBtRA",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/19aUQYZq02qHsCelO4eeV4sx_MTJJupC5qe0gDLQBtRA/edit?usp=drivesdk",
          "cachedResultName": "Sample Marketing Data"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "bd899d8c-dcf1-4894-a747-9b2b4ccef312",
      "name": "Sum spend by Day",
      "type": "n8n-nodes-base.summarize",
      "position": [
        -1200,
        1632
      ],
      "parameters": {
        "options": {},
        "fieldsToSplitBy": "Date",
        "fieldsToSummarize": {
          "values": [
            {
              "field": "Spend ($)",
              "aggregation": "sum"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "d9a73468-2205-4ca6-b11e-474a4110b4d3",
      "name": "Sort Dates Descending",
      "type": "n8n-nodes-base.code",
      "position": [
        -1008,
        1824
      ],
      "parameters": {
        "jsCode": "// 1. Grab all incoming items\nconst items = $input.all();\n\n// 2. Sort by your date field descending\nitems.sort((a, b) => {\n  const da = new Date(a.json.Date).getTime();\n  const db = new Date(b.json.Date).getTime();\n  return db - da;  // newest first\n});\n\n// 3. Return sorted items\nreturn items;\n"
      },
      "typeVersion": 2
    },
    {
      "id": "d373bb01-22d8-44d4-981e-1e2a922ef230",
      "name": "Keep only Last Day",
      "type": "n8n-nodes-base.set",
      "position": [
        -864,
        1616
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "e98f13e6-20a4-49fc-87cd-5b20f54f010c",
              "name": "Date",
              "type": "string",
              "value": "={{ $json.Date }}"
            },
            {
              "id": "a127b49d-dbfb-4143-a944-10d6e95e4e04",
              "name": "sum_Spend_($)",
              "type": "number",
              "value": "={{ $json['sum_Spend_($)'] }}"
            }
          ]
        }
      },
      "executeOnce": true,
      "typeVersion": 3.4
    },
    {
      "id": "b1c165e8-1f43-4305-8922-fcd9edc5df5b",
      "name": "Check if Spend over $100",
      "type": "n8n-nodes-base.if",
      "position": [
        -560,
        1808
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "6193ed35-58eb-4ca3-a0a2-9f0426ecce5e",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $json['sum_Spend_($)'] }}",
              "rightValue": 100
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "3a95cc4a-58c5-4e41-a6e7-da56cd32175d",
      "name": "Send Slack Message",
      "type": "n8n-nodes-base.slack",
      "position": [
        -320,
        1728
      ],
      "parameters": {
        "text": "The spend for the most recent day is over  $100",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C08T2J84F6C",
          "cachedResultName": "leads"
        },
        "otherOptions": {}
      },
      "typeVersion": 2.3
    },
    {
      "id": "058c5690-3644-4458-990b-173a52b418ae",
      "name": "Do Nothign. Under 100",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -288,
        1936
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "1c2a3061-8010-42ad-9885-244f19e71e77",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1888,
        1024
      ],
      "parameters": {
        "color": 5,
        "width": 560,
        "height": 1000,
        "content": "#### 1\ufe0f\u20e3 Schedule or Manual Trigger\n- **Node**: `Schedule Workflow` or `Test Workflow`\n- **Purpose**: Either run daily via a cron-like rule or manually trigger the flow.\n\n#### 2\ufe0f\u20e3 Get Google Sheet Data\n- **Node**: `Get Data`\n- **What it does**: Fetches all rows from your connected sheet.\n- **Setup**:\n  - Go to [Google Cloud Console](https://console.cloud.google.com/)\n  - Create a new project\n  - Enable **Google Sheets API**\n  - Create OAuth2 credentials for a desktop or web application\n  - Connect your Google account in n8n via OAuth2\n  - Grant access to the sheet you want to read (ensure it's shared with your OAuth email)\n  - Use the copied sheet's link when connecting in n8n\n\n\ud83d\udcce **Copy this Sample Google Sheet to Use:**  \n[Marketing Data Sheet - Copy Me](https://docs.google.com/spreadsheets/d/19aUQYZq02qHsCelO4eeV4sx_MTJJupC5qe0gDLQBtRA/edit?usp=sharing)\n"
      },
      "typeVersion": 1
    },
    {
      "id": "990dbac5-b790-43ee-9504-823629fc7877",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1280,
        1024
      ],
      "parameters": {
        "color": 6,
        "width": 600,
        "height": 1000,
        "content": "#### 3\ufe0f\u20e3 Summarize Spend by Day\n- **Node**: `Sum spend by Day`\n- **What it does**: Groups the dataset by `Date` and sums the `Spend ($)` column\n- **Requirements**:\n  - Your sheet must have a header row with `Date` and `Spend ($)` as columns\n\n#### 4\ufe0f\u20e3 Sort by Most Recent Date\n- **Node**: `Sort Dates Descending`\n- **What it does**: Sorts all entries by the `Date` field so that the most recent day is first\n- **Custom JavaScript**:\n```js\nconst items = $input.all();\nitems.sort((a, b) => new Date(b.json.Date) - new Date(a.json.Date));\nreturn items;\n```\n\n#### 5\ufe0f\u20e3 Select Top Result\n- **Node**: `Keep only Last Day`\n- **What it does**: Captures the top row (most recent day) for evaluation\n- **Fields**: Sets only `Date` and `sum_Spend_($)` to keep things clean"
      },
      "typeVersion": 1
    },
    {
      "id": "549bdcf3-d62a-479f-b8be-f1aea9bd8220",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -640,
        1024
      ],
      "parameters": {
        "color": 3,
        "width": 540,
        "height": 1000,
        "content": "#### 6\ufe0f\u20e3 Check Spend Threshold\n- **Node**: `Check if Spend over $100`\n- **What it does**: Uses an IF node to compare `sum_Spend_($)` against a 100 threshold\n- **Logic**:\n```json\nsum_Spend_($) > 100\n```\n\n#### 7\ufe0f\u20e3 Send Slack Notification\n- **Node**: `Send Slack Message`\n- **What it does**: Sends a message to a Slack channel if the threshold is exceeded\n- **Setup**:\n  - Go to [Slack API](https://api.slack.com/apps)\n  - Create a new app\n  - Enable **chat:write** and **channels:read** scopes under OAuth & Permissions\n  - Install the app to your workspace\n  - Copy the OAuth Token into your Slack credentials in n8n\n  - Select your target channel from the dropdown (must be public or the bot must be invited)\n- **Message**:\n  ```\n  The spend for the most recent day is over $100\n  ```\n\n#### 8\ufe0f\u20e3 No Action if Under Budget\n- **Node**: `Do Nothing. Under 100`\n- **Purpose**: This path simply ends the flow with no action if spend is below the threshold\n"
      },
      "typeVersion": 1
    },
    {
      "id": "cd548826-5af7-4685-b5b3-3af4c24790bb",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1888,
        864
      ],
      "parameters": {
        "width": 1780,
        "height": 120,
        "content": "### \ud83d\udc64 Need more help?\n**Robert Breen**  \nAutomation Consultant | AI Workflow Designer | n8n Expert  \n\ud83d\udce7 [rbreen@ynteractive.com](mailto:rbreen@ynteractive.com)  \n\ud83d\udd17 [LinkedIn](https://www.linkedin.com/in/robert-breen-29429625/)\n"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Get Data": {
      "main": [
        [
          {
            "node": "Sum spend by Day",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sum spend by Day": {
      "main": [
        [
          {
            "node": "Sort Dates Descending",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Workflow": {
      "main": [
        [
          {
            "node": "Get Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keep only Last Day": {
      "main": [
        [
          {
            "node": "Check if Spend over $100",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sort Dates Descending": {
      "main": [
        [
          {
            "node": "Keep only Last Day",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if Spend over $100": {
      "main": [
        [
          {
            "node": "Send Slack Message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Do Nothign. Under 100",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}