{
  "name": "Weekly report: the numbers, written up for Monday",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "30 7 * * 1"
            }
          ]
        }
      },
      "id": "d52dd7c6-ff37-5fb1-a472-3a3339a8a7d0",
      "name": "Mondays at 7:30",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "authentication": "appToken",
        "resource": "deal",
        "operation": "getAll",
        "returnAll": true,
        "filters": {
          "propertiesCollection": {
            "propertiesValues": {
              "properties": [
                "dealname",
                "amount",
                "dealstage",
                "closedate"
              ]
            }
          }
        }
      },
      "id": "a9a5f762-06f8-5a67-b18b-67766aa66cb7",
      "name": "Deals won last week",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 2,
      "position": [
        220,
        -80
      ],
      "credentials": {
        "hubspotAppToken": {
          "id": "",
          "name": "HubSpot"
        }
      }
    },
    {
      "parameters": {
        "url": "https://api.stripe.com/v1/charges",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "stripeApi",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "created[gte]",
              "value": "={{ Math.floor(Date.now() / 1000) - 7 * 86400 }}"
            },
            {
              "name": "limit",
              "value": "100"
            }
          ]
        },
        "options": {}
      },
      "id": "9640bf69-d489-57e5-bb5a-038751d72cb2",
      "name": "Payments last week",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        220,
        80
      ],
      "credentials": {
        "stripeApi": {
          "id": "",
          "name": "Stripe"
        }
      }
    },
    {
      "parameters": {
        "mode": "append"
      },
      "id": "0df7ba8a-a20a-5b2b-a572-a596cfa99841",
      "name": "Wait for both",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "const weekAgo = Date.now() - 7 * 86400 * 1000;\nconst all = $input.all().map((i) => i.json);\nconst deals = all.filter((d) => (d.properties ?? d).dealstage === 'closedwon' && new Date((d.properties ?? d).closedate).getTime() > weekAgo);\nconst charges = all.flatMap((r) => r.data ?? []).filter((c) => c.paid && !c.refunded);\nconst won = deals.reduce((n, d) => n + Number((d.properties ?? d).amount ?? 0), 0);\nconst cash = charges.reduce((n, c) => n + c.amount / 100, 0);\nreturn [{ json: { deals_won: deals.length, value_won: won, payments: charges.length, cash_in: cash } }];"
      },
      "id": "27f3efad-9bb2-50ab-a875-f3bde269d4cb",
      "name": "Add up the week",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        660,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.anthropic.com/v1/messages",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "anthropic-version",
              "value": "2023-06-01"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: 'claude-sonnet-5-5', max_tokens: 300, system: \"Write a short Monday-morning business update for the owner: three sentences, plain English, numbers exact, no hype. Mention anything unusual.\", messages: [{ role: 'user', content: `Last week: ${$json.deals_won} deals won worth $${$json.value_won}. ${$json.payments} payments collected, $${$json.cash_in} in total.` }] }) }}",
        "options": {
          "timeout": 60000
        }
      },
      "id": "4fec01f0-0e7b-5009-9020-aff54cb63c51",
      "name": "Write the summary with Claude",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "",
          "name": "Anthropic API key (header x-api-key)"
        }
      }
    },
    {
      "parameters": {
        "sendTo": "owner@yourcompany.com",
        "subject": "=Your week in numbers, {{ $now.minus({ days: 7 }).toFormat('d LLL') }} to {{ $now.toFormat('d LLL') }}",
        "emailType": "text",
        "message": "={{ $json.content?.[0]?.text }}",
        "options": {}
      },
      "id": "fc6b9868-5702-550c-bdf1-dfc5f00885bd",
      "name": "Email the owner",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1100,
        0
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "",
          "name": "Gmail"
        }
      }
    }
  ],
  "connections": {
    "Mondays at 7:30": {
      "main": [
        [
          {
            "node": "Deals won last week",
            "type": "main",
            "index": 0
          },
          {
            "node": "Payments last week",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Deals won last week": {
      "main": [
        [
          {
            "node": "Wait for both",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Payments last week": {
      "main": [
        [
          {
            "node": "Wait for both",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Wait for both": {
      "main": [
        [
          {
            "node": "Add up the week",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add up the week": {
      "main": [
        [
          {
            "node": "Write the summary with Claude",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write the summary with Claude": {
      "main": [
        [
          {
            "node": "Email the owner",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false,
    "adev": {
      "slug": "weekly-report",
      "service": "ai-automation",
      "needs": [
        "n8n",
        "Anthropic API key",
        "HubSpot",
        "Stripe",
        "Gmail"
      ],
      "summary": "Every Monday at 7:30 the week's won deals and payments are added up and written into a three-sentence update in the owner's inbox."
    }
  },
  "tags": [
    {
      "name": "adev.build"
    }
  ]
}