{
  "name": "Valkiria: daily spend digest to Slack",
  "nodes": [
    {
      "parameters": { "rule": { "interval": [{ "field": "cronExpression", "expression": "0 8 * * *" }] } },
      "id": "a1f0c6d2-0001-4a00-9000-000000000001",
      "name": "Every day 08:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [0, 0]
    },
    {
      "parameters": {
        "url": "https://valkiria.pro/api/v1/analytics/spend",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendQuery": true,
        "queryParameters": { "parameters": [{ "name": "period", "value": "7d" }, { "name": "group_by", "value": "day" }] },
        "options": {}
      },
      "id": "a1f0c6d2-0001-4a00-9000-000000000002",
      "name": "Valkiria spend, 7 days",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [220, 0],
      "credentials": { "httpHeaderAuth": { "id": "", "name": "Valkiria API key" } }
    },
    {
      "parameters": {
        "jsCode": "const s = $input.first().json;\nconst days = s.timeline || [];\nconst last = days[days.length - 1];\nconst money = (v, c) => v === null || v === undefined ? 'n/a' : `${v.toFixed(2)} ${c || ''}`.trim();\nconst lines = Object.entries(s.byCurrency || {}).map(([c, b]) => `• ${c}: spend ${money(b.totalSpend, c)}, revenue ${money(b.totalRevenue, c)}, ROAS ${b.roas ?? 'n/a'}`);\nconst text = [\n  `*Ad spend, last 7 days*`,\n  ...lines,\n  last ? `Latest day ${String(last.period_start).slice(0, 10)}: ${money(last.spend, last.currency)}, ${last.conversions ?? 'n/a'} conversions` : 'No spend recorded in the period.',\n].join(String.fromCharCode(10));\nreturn [{ json: { text } }];"
      },
      "id": "a1f0c6d2-0001-4a00-9000-000000000003",
      "name": "Format digest",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [440, 0]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://hooks.slack.com/services/REPLACE/WITH/YOUR_WEBHOOK",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ text: $json.text }) }}",
        "options": {}
      },
      "id": "a1f0c6d2-0001-4a00-9000-000000000004",
      "name": "Post to Slack",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [660, 0]
    }
  ],
  "connections": {
    "Every day 08:00": { "main": [[{ "node": "Valkiria spend, 7 days", "type": "main", "index": 0 }]] },
    "Valkiria spend, 7 days": { "main": [[{ "node": "Format digest", "type": "main", "index": 0 }]] },
    "Format digest": { "main": [[{ "node": "Post to Slack", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" },
  "pinData": {}
}
