{
  "id": "5if9twDNChTpUQFf",
  "name": "Generate Weekly Energy Consumption Reports with API, Email and Google Drive",
  "tags": [],
  "nodes": [
    {
      "id": "4827c44f-1995-4cd9-837f-f06c55ce9697",
      "name": "Schedule Weekly (Mon 8AM)",
      "type": "n8n-nodes-base.cron",
      "position": [
        -200,
        200
      ],
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "hour": 8,
              "mode": "everyWeek",
              "weekday": "monday"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "028bf36b-a75b-474d-a596-dcd8f4db7c20",
      "name": "Fetch Energy Data",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        20,
        200
      ],
      "parameters": {
        "url": "https://api.energidataservice.dk/dataset/ConsumptionDE35Hour",
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "f0fa171b-52b2-4350-8d0f-808117715e30",
      "name": "Normalize Records",
      "type": "n8n-nodes-base.code",
      "position": [
        240,
        200
      ],
      "parameters": {
        "jsCode": "const itemlist = $input.first().json.records;\nreturn itemlist.map(r => ({ json: r }));"
      },
      "typeVersion": 2
    },
    {
      "id": "a47b2980-6da2-4dbc-bb09-d23d4b936d9f",
      "name": "Convert to File",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        460,
        200
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "613baa2d-3929-4e88-aa65-5303860dcfb4",
      "name": "Send Email Weekly Report",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        680,
        100
      ],
      "parameters": {
        "text": "Please find attached the latest weekly energy consumption report.",
        "options": {},
        "subject": "Weekly Energy Consumption Report",
        "toEmail": "user@example.com",
        "fromEmail": "user@example.com",
        "attachments": "=data"
      },
      "typeVersion": 1
    },
    {
      "id": "588f3a86-3932-499f-b3aa-e60cbc2c8ebd",
      "name": "Report File Upload to Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        680,
        300
      ],
      "parameters": {
        "name": "=energy_report_{{ $now.format('yyyy_MM_dd_HH_ii_ss') }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "root",
          "cachedResultName": "/ (Root folder)"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "7c910c92-a9d4-4a2e-9e91-69d859ea633f",
      "name": "Sticky: Node Explanations1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        40
      ],
      "parameters": {
        "width": 160,
        "height": 120,
        "content": "\ud83d\udcdd - **Schedule Weekly (Mon 8AM)**: Trigger every Monday at 8AM."
      },
      "typeVersion": 1
    },
    {
      "id": "ff3f08c5-430d-4b3e-8ef5-f3f93d32efe7",
      "name": "Sticky: Node Explanations2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -20,
        40
      ],
      "parameters": {
        "width": 160,
        "height": 120,
        "content": "\ud83d\udcdd - **Fetch Energy Data**: Call EnergiDataService.dk API."
      },
      "typeVersion": 1
    },
    {
      "id": "1627fcfa-d1f6-40f5-90dd-0352b2a6fb63",
      "name": "Sticky: Node Explanations3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        200,
        40
      ],
      "parameters": {
        "width": 160,
        "height": 120,
        "content": "\ud83d\udcdd - **Normalize Records**: Flatten JSON response (records \u2192 items)."
      },
      "typeVersion": 1
    },
    {
      "id": "48440a87-317b-47e4-808c-b07e6411bdd0",
      "name": "Sticky: Node Explanations4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        420,
        40
      ],
      "parameters": {
        "width": 160,
        "height": 120,
        "content": "\ud83d\udcdd - **Convert to File**: Turn items into a CSV (binary `data`)."
      },
      "typeVersion": 1
    },
    {
      "id": "dd003fb3-dccc-4e2f-90d4-f9acbdcca301",
      "name": "Sticky: Node Explanations5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        660,
        -40
      ],
      "parameters": {
        "width": 160,
        "height": 120,
        "content": "\ud83d\udcdd - **Email Weekly Report**: Email the CSV file."
      },
      "typeVersion": 1
    },
    {
      "id": "2f2425e1-86d2-499c-be72-3f42d723385c",
      "name": "Sticky: Node Explanations6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        660,
        500
      ],
      "parameters": {
        "width": 160,
        "height": 120,
        "content": "\ud83d\udcdd - **Upload File to Drive**: Save CSV to Google Drive."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "c9007e5b-7c88-4384-97bf-12dff0a2672c",
  "connections": {
    "Convert to File": {
      "main": [
        [
          {
            "node": "Send Email Weekly Report",
            "type": "main",
            "index": 0
          },
          {
            "node": "Report File Upload to Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Energy Data": {
      "main": [
        [
          {
            "node": "Normalize Records",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Records": {
      "main": [
        [
          {
            "node": "Convert to File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Weekly (Mon 8AM)": {
      "main": [
        [
          {
            "node": "Fetch Energy Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}