{
  "name": "BEL'R — Export quotidien ICS vers Nextcloud",
  "nodes": [
    {
      "parameters": {
        "rule": { "interval": [{ "field": "hours", "hoursInterval": 6 }] }
      },
      "id": "schedule",
      "name": "Planificateur — toutes les 6h",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.1,
      "position": [240, 300]
    },
    {
      "parameters": {
        "url": "https://nextcloud.belr-hautanjou.fr/remote.php/dav/public-calendars/44LKnByfDDsznDzq?export",
        "options": { "timeout": 30000 }
      },
      "id": "fetch-belr",
      "name": "Fetch ICS — BEL'R",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [460, 200]
    },
    {
      "parameters": {
        "url": "https://nextcloud.belr-hautanjou.fr/remote.php/dav/public-calendars/CbraTTLxqF6MpfCX?export",
        "options": { "timeout": 30000 }
      },
      "id": "fetch-partenaires",
      "name": "Fetch ICS — Partenaires",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [460, 340]
    },
    {
      "parameters": {
        "url": "https://nextcloud.belr-hautanjou.fr/remote.php/dav/public-calendars/NK5jnj9ePNnS98GG?export",
        "options": { "timeout": 30000 }
      },
      "id": "fetch-territoire",
      "name": "Fetch ICS — Territoire",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [460, 480]
    },
    {
      "parameters": {
        "method": "PUT",
        "url": "https://nextcloud.belr-hautanjou.fr/remote.php/dav/files/belr-export/calendars/belr.ics",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth",
        "sendBody": true,
        "contentType": "raw",
        "rawContentType": "text/calendar; charset=utf-8",
        "body": "={{ $('Fetch ICS — BEL\\'R').item.json }}",
        "options": {}
      },
      "id": "upload-belr",
      "name": "Upload vers Nextcloud — belr.ics",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [700, 200],
      "notes": "Credentials : compte Nextcloud avec accès WebDAV au dossier /calendars/"
    },
    {
      "parameters": {
        "method": "PUT",
        "url": "https://nextcloud.belr-hautanjou.fr/remote.php/dav/files/belr-export/calendars/partenaires.ics",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth",
        "sendBody": true,
        "contentType": "raw",
        "rawContentType": "text/calendar; charset=utf-8",
        "body": "={{ $('Fetch ICS — Partenaires').item.json }}",
        "options": {}
      },
      "id": "upload-partenaires",
      "name": "Upload vers Nextcloud — partenaires.ics",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [700, 340]
    },
    {
      "parameters": {
        "method": "PUT",
        "url": "https://nextcloud.belr-hautanjou.fr/remote.php/dav/files/belr-export/calendars/territoire.ics",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth",
        "sendBody": true,
        "contentType": "raw",
        "rawContentType": "text/calendar; charset=utf-8",
        "body": "={{ $('Fetch ICS — Territoire').item.json }}",
        "options": {}
      },
      "id": "upload-territoire",
      "name": "Upload vers Nextcloud — territoire.ics",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [700, 480]
    },
    {
      "parameters": {
        "method": "MKCOL",
        "url": "https://nextcloud.belr-hautanjou.fr/remote.php/dav/files/belr-export/calendars/",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth",
        "options": {}
      },
      "id": "ensure-folder",
      "name": "Créer dossier si absent (MKCOL)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [460, 620],
      "notes": "MKCOL retourne 405 si le dossier existe déjà — normal, ignorer l'erreur"
    }
  ],
  "connections": {
    "Planificateur — toutes les 6h": {
      "main": [[
        { "node": "Fetch ICS — BEL'R", "type": "main", "index": 0 },
        { "node": "Fetch ICS — Partenaires", "type": "main", "index": 0 },
        { "node": "Fetch ICS — Territoire", "type": "main", "index": 0 },
        { "node": "Créer dossier si absent (MKCOL)", "type": "main", "index": 0 }
      ]]
    },
    "Fetch ICS — BEL'R":        { "main": [[{ "node": "Upload vers Nextcloud — belr.ics",        "type": "main", "index": 0 }]] },
    "Fetch ICS — Partenaires":  { "main": [[{ "node": "Upload vers Nextcloud — partenaires.ics", "type": "main", "index": 0 }]] },
    "Fetch ICS — Territoire":   { "main": [[{ "node": "Upload vers Nextcloud — territoire.ics",  "type": "main", "index": 0 }]] }
  },
  "settings": {
    "executionOrder": "v1",
    "errorWorkflow": ""
  },
  "notes": "Exporte les 3 calendriers Nextcloud vers des fichiers ICS statiques dans Nextcloud.\nCes fichiers sont ensuite synchronisés vers le dossier static/calendars/ du site Hugo (via rsync ou Nextcloud WebDAV).\n\nConfiguration requise :\n1. Créer des credentials HTTP Basic Auth dans N8N avec un compte Nextcloud\n2. Le compte doit avoir accès en écriture à /remote.php/dav/files/belr-export/calendars/\n3. Configurer rsync ou un hook de déploiement pour copier les ICS vers le site Hugo",
  "tags": ["BEL'R", "Agenda", "Cron"]
}
