The workflow JSON
Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →
{
"name": "[VOTRE_AGENCE] \u2014 9. Cron Nettoyage",
"nodes": [
{
"parameters": {
"rule": {
"interval": [
{
"field": "cronExpression",
"expression": "0 23 * * *"
}
]
}
},
"id": "bba384e6-0615-4041-a5aa-ddeb9244babb",
"name": "Cron \u2014 Minuit WAT (23h UTC)",
"type": "n8n-nodes-base.scheduleTrigger",
"typeVersion": 1,
"position": [
0,
0
],
"notes": "B\u00e9nin = UTC+1. Minuit WAT = 23h UTC."
},
{
"parameters": {
"method": "PATCH",
"url": "=https://YOUR_PROJECT_REF.supabase.co/rest/v1/commandes?statut=eq.en_attente&livreur_id=is.null&created_at=lt.{{ new Date(Date.now() - 3600000).toISOString() }}",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "apikey",
"value": "YOUR_SUPABASE_SERVICE_ROLE_KEY"
},
{
"name": "Authorization",
"value": "Bearer YOUR_SUPABASE_SERVICE_ROLE_KEY"
},
{
"name": "Content-Type",
"value": "application/json"
},
{
"name": "Prefer",
"value": "return=minimal"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "{ \"statut\": \"annulee\" }",
"options": {}
},
"id": "2a8fc4a4-54f6-4039-97fe-ba38e08c8eff",
"name": "PATCH \u2014 Commandes orphelines \u2192 annulee",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4,
"position": [
272,
0
],
"notes": "Annule les commandes en_attente sans livreur_id depuis > 1h."
},
{
"parameters": {
"method": "PATCH",
"url": "=https://YOUR_PROJECT_REF.supabase.co/rest/v1/commandes?statut=eq.recherche_livreur&created_at=lt.{{ new Date(Date.now() - 3600000).toISOString() }}",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "apikey",
"value": "YOUR_SUPABASE_SERVICE_ROLE_KEY"
},
{
"name": "Authorization",
"value": "Bearer YOUR_SUPABASE_SERVICE_ROLE_KEY"
},
{
"name": "Content-Type",
"value": "application/json"
},
{
"name": "Prefer",
"value": "return=minimal"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "{ \"statut\": \"annulee\", \"livreur_id\": null }",
"options": {}
},
"id": "daf3363d-0ded-4d0a-80b6-ed24bfddb0ff",
"name": "PATCH \u2014 recherche_livreur bloqu\u00e9e \u2192 annulee",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4,
"position": [
528,
0
],
"notes": "Annule les commandes bloqu\u00e9es en recherche_livreur depuis > 1h."
},
{
"parameters": {
"method": "PATCH",
"url": "=https://YOUR_PROJECT_REF.supabase.co/rest/v1/sessions?updated_at=lt.{{ new Date(Date.now() - 86400000).toISOString() }}",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "apikey",
"value": "YOUR_SUPABASE_SERVICE_ROLE_KEY"
},
{
"name": "Authorization",
"value": "Bearer YOUR_SUPABASE_SERVICE_ROLE_KEY"
},
{
"name": "Content-Type",
"value": "application/json"
},
{
"name": "Prefer",
"value": "return=minimal"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "{ \"etape\": \"idle\", \"commande_temp\": \"{}\", \"contexte\": \"{}\" }",
"options": {}
},
"id": "7ae3ba7d-1997-418f-a76d-e52f13844619",
"name": "PATCH \u2014 Sessions inactives \u2192 idle",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4,
"position": [
784,
0
],
"notes": "Reset les sessions vendeur inactives depuis > 24h."
},
{
"parameters": {
"url": "https://YOUR_PROJECT_REF.supabase.co/rest/v1/commandes?select=id&or=(statut.eq.en_cours,statut.eq.acceptee,statut.eq.en_route_recup,statut.eq.colis_recupere)",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "apikey",
"value": "YOUR_SUPABASE_SERVICE_ROLE_KEY"
},
{
"name": "Authorization",
"value": "Bearer YOUR_SUPABASE_SERVICE_ROLE_KEY"
}
]
},
"options": {}
},
"id": "359ef6b8-cee5-4ef0-80b5-d670ef53a28e",
"name": "GET \u2014 Commandes actives (livreur_ids)",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4,
"position": [
1040,
0
],
"alwaysOutputData": true,
"notes": "R\u00e9cup\u00e8re les IDs commandes encore actives pour ne pas reset les livreurs concern\u00e9s."
},
{
"parameters": {
"jsCode": "// Construit la liste des livreur_id encore actifs (commandes en cours)\nconst items = $input.all();\nconst livreurIds = items\n .map(i => i.json.livreur_id)\n .filter(id => id && id !== null);\n\n// Si aucune commande active, on peut reset tous les livreurs occupe\nreturn [{ json: { livreur_ids_actifs: livreurIds, count: livreurIds.length } }];"
},
"id": "4509a29f-4e25-44a4-99e2-73eb30041153",
"name": "Parser \u2014 Livreurs encore actifs",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1312,
0
],
"notes": "Pr\u00e9pare la liste des livreurs \u00e0 NE PAS reset."
},
{
"parameters": {
"method": "PATCH",
"url": "https://YOUR_PROJECT_REF.supabase.co/rest/v1/livreurs?statut=eq.occupe",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "apikey",
"value": "YOUR_SUPABASE_SERVICE_ROLE_KEY"
},
{
"name": "Authorization",
"value": "Bearer YOUR_SUPABASE_SERVICE_ROLE_KEY"
},
{
"name": "Content-Type",
"value": "application/json"
},
{
"name": "Prefer",
"value": "return=minimal"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "{ \"statut\": \"disponible\" }",
"options": {}
},
"id": "6ccdbd05-6c02-4b6c-9abd-140e88ac6cdb",
"name": "PATCH \u2014 Livreurs occupe \u2192 disponible",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4,
"position": [
1568,
0
],
"notes": "Reset tous les livreurs bloqu\u00e9s en occupe sans commande active. Pas de updated_at (colonne absente)."
},
{
"parameters": {
"method": "PATCH",
"url": "https://YOUR_PROJECT_REF.supabase.co/rest/v1/notifications_course?statut=eq.envoyee",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "apikey",
"value": "YOUR_SUPABASE_SERVICE_ROLE_KEY"
},
{
"name": "Authorization",
"value": "Bearer YOUR_SUPABASE_SERVICE_ROLE_KEY"
},
{
"name": "Content-Type",
"value": "application/json"
},
{
"name": "Prefer",
"value": "return=minimal"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "{ \"statut\": \"expiree\" }",
"options": {}
},
"id": "e36d9aba-38fc-4dea-a5e1-4369f2a67c64",
"name": "PATCH \u2014 Notifs envoyee r\u00e9siduelles \u2192 expiree",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4,
"position": [
1824,
0
],
"notes": "Nettoie les notifications_course rest\u00e9es en envoyee (normalement d\u00e9j\u00e0 trait\u00e9es par W8)."
},
{
"parameters": {
"url": "=https://YOUR_PROJECT_REF.supabase.co/rest/v1/commandes?statut=eq.livree&created_at=gte.{{ new Date(new Date().setHours(0,0,0,0) - 3600000).toISOString() }}&select=id,prix,telephone_vendeur,commande_data,created_at,updated_at",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "apikey",
"value": "YOUR_SUPABASE_SERVICE_ROLE_KEY"
},
{
"name": "Authorization",
"value": "Bearer YOUR_SUPABASE_SERVICE_ROLE_KEY"
}
]
},
"options": {}
},
"id": "2a00ecf9-20b2-4abd-911b-0829279129b7",
"name": "GET \u2014 Commandes livr\u00e9es du jour",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4,
"position": [
2080,
0
],
"notes": "R\u00e9cup\u00e8re les commandes livr\u00e9es aujourd'hui pour le rapport Sophie."
},
{
"parameters": {
"jsCode": "const items = $input.all();\nconst commandes = items.map(i => i.json).filter(c => c.id);\n\nconst now = new Date(Date.now() + 3600000); // WAT\nconst dateStr = now.toLocaleDateString('fr-FR', { weekday: 'long', day: 'numeric', month: 'long' });\n\nconst nbLivraisons = commandes.length;\nconst totalFCFA = commandes.reduce((sum, c) => sum + (c.prix || 0), 0);\n\nlet details = '';\ncommandes.forEach((c, idx) => {\n let cd = c.commande_data;\n if (typeof cd === 'string') cd = JSON.parse(cd);\n const zone = cd?.zone_recup || '?';\n const nb = cd?.colis?.length || 1;\n details += `\\n\u2022 Commande ${idx+1} \u2014 ${zone} \u2014 ${nb} colis \u2014 ${c.prix || 0} FCFA`;\n});\n\nconst message = nbLivraisons === 0\n ? `\ud83d\udcca *Rapport du ${dateStr}*\\n\\nAucune livraison effectu\u00e9e aujourd'hui.\\n\\n_Syst\u00e8me nettoy\u00e9 \u2705_`\n : `\ud83d\udcca *Rapport du ${dateStr}*\\n\\n\u2705 *${nbLivraisons} livraison${nbLivraisons > 1 ? 's' : ''} effectu\u00e9e${nbLivraisons > 1 ? 's' : ''}*\\n\ud83d\udcb0 *Total encaiss\u00e9 : ${totalFCFA.toLocaleString('fr-FR')} FCFA*\\n${details}\\n\\n_Syst\u00e8me nettoy\u00e9 \u2705_`;\n\nreturn [{ json: { message } }];"
},
"id": "d213090e-5af3-46a0-b3cd-4320fdd9ea5d",
"name": "Construire Rapport Journalier",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
2352,
0
],
"notes": "Rapport journalier \u00e0 envoyer \u00e0 Sophie \u00e0 minuit WAT."
},
{
"parameters": {
"method": "POST",
"url": "https://graph.facebook.com/v19.0/YOUR_WHATSAPP_PHONE_NUMBER_ID/messages",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "Bearer YOUR_WHATSAPP_ACCESS_TOKEN"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"messaging_product\": \"whatsapp\",\n \"to\": \"22900000001\",\n \"type\": \"text\",\n \"text\": { \"body\": {{ JSON.stringify($json.message) }} }\n}",
"options": {}
},
"id": "97adcdc0-abd9-4afa-9626-14c332b5c653",
"name": "WA Sophie \u2014 Rapport Journalier",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4,
"position": [
2608,
0
],
"notes": "Envoie le rapport de fin de journ\u00e9e \u00e0 Sophie par WhatsApp."
}
],
"connections": {
"Cron \u2014 Minuit WAT (23h UTC)": {
"main": [
[
{
"node": "PATCH \u2014 Commandes orphelines \u2192 annulee",
"type": "main",
"index": 0
}
]
]
},
"PATCH \u2014 Commandes orphelines \u2192 annulee": {
"main": [
[
{
"node": "PATCH \u2014 recherche_livreur bloqu\u00e9e \u2192 annulee",
"type": "main",
"index": 0
}
]
]
},
"PATCH \u2014 recherche_livreur bloqu\u00e9e \u2192 annulee": {
"main": [
[
{
"node": "PATCH \u2014 Sessions inactives \u2192 idle",
"type": "main",
"index": 0
}
]
]
},
"PATCH \u2014 Sessions inactives \u2192 idle": {
"main": [
[
{
"node": "GET \u2014 Commandes actives (livreur_ids)",
"type": "main",
"index": 0
}
]
]
},
"GET \u2014 Commandes actives (livreur_ids)": {
"main": [
[
{
"node": "Parser \u2014 Livreurs encore actifs",
"type": "main",
"index": 0
}
]
]
},
"Parser \u2014 Livreurs encore actifs": {
"main": [
[
{
"node": "PATCH \u2014 Livreurs occupe \u2192 disponible",
"type": "main",
"index": 0
}
]
]
},
"PATCH \u2014 Livreurs occupe \u2192 disponible": {
"main": [
[
{
"node": "PATCH \u2014 Notifs envoyee r\u00e9siduelles \u2192 expiree",
"type": "main",
"index": 0
}
]
]
},
"PATCH \u2014 Notifs envoyee r\u00e9siduelles \u2192 expiree": {
"main": [
[
{
"node": "GET \u2014 Commandes livr\u00e9es du jour",
"type": "main",
"index": 0
}
]
]
},
"GET \u2014 Commandes livr\u00e9es du jour": {
"main": [
[
{
"node": "Construire Rapport Journalier",
"type": "main",
"index": 0
}
]
]
},
"Construire Rapport Journalier": {
"main": [
[
{
"node": "WA Sophie \u2014 Rapport Journalier",
"type": "main",
"index": 0
}
]
]
}
},
"active": true,
"settings": {
"executionOrder": "v1",
"binaryMode": "separate",
"availableInMCP": false,
"timeSavedMode": "fixed",
"errorWorkflow": "rMPoeScqXxkqMAOO",
"callerPolicy": "workflowsFromSameOwner"
},
"versionId": "3c20cfda-019e-4d50-be6d-42a90080b985",
"nodeGroups": [],
"id": "p7ySVJ3JDDbyObpL",
"tags": []
}
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
[VOTRE_AGENCE] — 9. Cron Nettoyage. Uses httpRequest. Scheduled trigger; 11 nodes.
Source: https://github.com/Digitalhorizonagency1/delivery/blob/15130ecbecbf625ffc17e7f45b4ecd55a16c2077/n8n-workflows/W9-cron-nettoyage.json — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
Birthday Automation - Production (Fixed). Uses stopAndError, httpRequest, emailSend, bannerbear. Scheduled trigger; 86 nodes.
This template runs two scheduled workflows to govern Microsoft Entra ID (Azure AD) guest accounts by detecting stale users via Microsoft Graph, staging deletions in SharePoint with a 72-hour window, n
Jira-Allure-Auto-Qa. Uses httpRequest, jira. Scheduled trigger; 68 nodes.
Spotify-Sync-Surrealdb-V1. Uses httpRequest, n8n-nodes-surrealdb, spotify. Scheduled trigger; 62 nodes.
As n8n instances scale, teams often lose track of sub-workflows—who uses them, where they are referenced, and whether they can be safely updated. This leads to inefficiencies like unnecessary copies o