Skip to main content
Glama
event-creation.json17.4 kB
{ "name": "Template - Création d'événements Google Calendar", "nodes": [ { "parameters": { "httpMethod": "POST", "path": "create-event", "options": { "responseMode": "responseNode" }, "authentication": "basicAuth", "responseCode": "200", "responseContentType": "application/json", "responsePropertyName": "data" }, "id": "webhook-trigger", "name": "Webhook - Réception requête", "type": "n8n-nodes-base.webhook", "typeVersion": 1, "position": [ 250, 300 ], "webhookId": "create-event" }, { "parameters": { "jsCode": "// Récupération des données d'entrée\nconst input = $input.item.json.body || $input.item.json;\n\n// Validation des champs requis\nconst requiredFields = ['summary', 'start', 'end'];\nconst missingFields = [];\n\nfor (const field of requiredFields) {\n if (!input[field]) {\n missingFields.push(field);\n }\n}\n\nif (missingFields.length > 0) {\n return {\n error: true,\n message: `Champs requis manquants: ${missingFields.join(', ')}`,\n statusCode: 400\n };\n}\n\n// Validation des formats de date\nfunction isValidDate(dateStr) {\n // Accepte les formats ISO 8601 ou les objets avec dateTime/timeZone\n if (typeof dateStr === 'string') {\n return !isNaN(new Date(dateStr).getTime());\n } else if (typeof dateStr === 'object') {\n if (dateStr.dateTime) {\n return !isNaN(new Date(dateStr.dateTime).getTime());\n }\n }\n return false;\n}\n\nif (!isValidDate(input.start) || !isValidDate(input.end)) {\n return {\n error: true,\n message: 'Format de date invalide. Utilisez le format ISO 8601 ou un objet {dateTime, timeZone}',\n statusCode: 400\n };\n}\n\n// Formatage des dates si nécessaire\nfunction formatDate(dateInput) {\n if (typeof dateInput === 'string') {\n // Convertir en objet Google Calendar\n const date = new Date(dateInput);\n return {\n dateTime: date.toISOString(),\n timeZone: input.timeZone || 'Europe/Paris'\n };\n }\n // Déjà au bon format\n return dateInput;\n}\n\n// Préparation des données pour Google Calendar\nconst eventData = {\n summary: input.summary,\n description: input.description || '',\n location: input.location || '',\n start: formatDate(input.start),\n end: formatDate(input.end),\n attendees: input.attendees || [],\n reminders: input.reminders || {\n useDefault: true\n },\n colorId: input.colorId || '',\n transparency: input.transparency || 'opaque',\n visibility: input.visibility || 'default'\n};\n\n// Ajout d'un identifiant unique pour le suivi\neventData.extendedProperties = {\n private: {\n createdBy: 'n8n-template',\n requestId: $execution.id\n }\n};\n\nreturn {\n eventData,\n calendarId: input.calendarId || 'primary'\n};" }, "id": "validate-format-data", "name": "Validation et formatage des données", "type": "n8n-nodes-base.code", "typeVersion": 1, "position": [ 450, 300 ] }, { "parameters": { "conditions": { "string": [ { "value1": "={{ $json.error }}", "operation": "exists" } ] } }, "id": "check-validation-errors", "name": "Vérification des erreurs de validation", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [ 650, 300 ] }, { "parameters": { "respondWith": "json", "responseBody": "={{ $json }}", "options": { "responseCode": "={{ $json.statusCode || 400 }}" } }, "id": "respond-validation-error", "name": "Répondre - Erreur de validation", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1, "position": [ 850, 200 ] }, { "parameters": { "resource": "calendar", "operation": "get", "calendarId": "={{ $json.calendarId }}" }, "id": "check-calendar-exists", "name": "Vérifier l'existence du calendrier", "type": "n8n-nodes-base.googleCalendar", "typeVersion": 2, "position": [ 850, 400 ], "credentials": { "googleCalendarOAuth2Api": { "id": "1", "name": "Google Calendar OAuth2 API" } }, "continueOnFail": true }, { "parameters": { "conditions": { "string": [ { "value1": "={{ $json.error }}", "operation": "exists" } ] } }, "id": "check-calendar-error", "name": "Vérification erreur calendrier", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [ 1050, 400 ] }, { "parameters": { "respondWith": "json", "responseBody": "={\n \"error\": true,\n \"message\": \"Calendrier non trouvé ou erreur d'accès: \" + $json.error.message,\n \"statusCode\": 404\n}", "options": { "responseCode": 404 } }, "id": "respond-calendar-error", "name": "Répondre - Erreur calendrier", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1, "position": [ 1250, 300 ] }, { "parameters": { "resource": "freeBusy", "calendarIds": { "calendarIds": [ "={{ $('check-calendar-exists').item.json.id }}" ] }, "options": { "timeMin": "={{ $('validate-format-data').item.json.eventData.start.dateTime }}", "timeMax": "={{ $('validate-format-data').item.json.eventData.end.dateTime }}" } }, "id": "check-availability", "name": "Vérification disponibilité", "type": "n8n-nodes-base.googleCalendar", "typeVersion": 2, "position": [ 1250, 500 ], "credentials": { "googleCalendarOAuth2Api": { "id": "1", "name": "Google Calendar OAuth2 API" } }, "continueOnFail": true }, { "parameters": { "jsCode": "// Analyse des résultats de disponibilité\nconst calendarId = $('check-calendar-exists').item.json.id;\nconst busyPeriods = $input.item.json.calendars[calendarId]?.busy || [];\n\n// Vérifier s'il y a des conflits\nif (busyPeriods.length > 0) {\n return {\n hasConflicts: true,\n conflicts: busyPeriods,\n message: \"Des conflits ont été détectés avec d'autres événements\"\n };\n} else {\n return {\n hasConflicts: false\n };\n}" }, "id": "analyze-conflicts", "name": "Analyse des conflits", "type": "n8n-nodes-base.code", "typeVersion": 1, "position": [ 1450, 500 ] }, { "parameters": { "conditions": { "boolean": [ { "value1": "={{ $json.hasConflicts }}", "value2": true } ] } }, "id": "check-conflicts", "name": "Vérification des conflits", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [ 1650, 500 ] }, { "parameters": { "respondWith": "json", "responseBody": "={\n \"error\": true,\n \"message\": \"Conflit détecté avec d'autres événements\",\n \"conflicts\": $json.conflicts,\n \"statusCode\": 409\n}", "options": { "responseCode": 409 } }, "id": "respond-conflict", "name": "Répondre - Conflit", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1, "position": [ 1850, 400 ] }, { "parameters": { "resource": "event", "operation": "create", "calendarId": "={{ $('validate-format-data').item.json.calendarId }}", "eventTitle": "={{ $('validate-format-data').item.json.eventData.summary }}", "start": "={{ $('validate-format-data').item.json.eventData.start }}", "end": "={{ $('validate-format-data').item.json.eventData.end }}", "additionalFields": { "description": "={{ $('validate-format-data').item.json.eventData.description }}", "location": "={{ $('validate-format-data').item.json.eventData.location }}", "attendees": "={{ $('validate-format-data').item.json.eventData.attendees }}", "reminders": "={{ $('validate-format-data').item.json.eventData.reminders }}", "extendedProperties": "={{ $('validate-format-data').item.json.eventData.extendedProperties }}", "colorId": "={{ $('validate-format-data').item.json.eventData.colorId }}", "transparency": "={{ $('validate-format-data').item.json.eventData.transparency }}", "visibility": "={{ $('validate-format-data').item.json.eventData.visibility }}" } }, "id": "create-event", "name": "Création de l'événement", "type": "n8n-nodes-base.googleCalendar", "typeVersion": 2, "position": [ 1850, 600 ], "credentials": { "googleCalendarOAuth2Api": { "id": "1", "name": "Google Calendar OAuth2 API" } }, "continueOnFail": true }, { "parameters": { "conditions": { "string": [ { "value1": "={{ $json.error }}", "operation": "exists" } ] } }, "id": "check-creation-error", "name": "Vérification erreur création", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [ 2050, 600 ] }, { "parameters": { "jsCode": "// Gestion des erreurs d'API Google Calendar\nconst error = $input.item.json.error;\n\n// Vérifier si c'est une erreur d'authentification\nif (error.message && (error.message.includes('401') || error.message.includes('auth'))) {\n return {\n error: true,\n authError: true,\n message: \"Erreur d'authentification. Le token OAuth doit être rafraîchi.\",\n originalError: error.message,\n statusCode: 401\n };\n}\n\n// Vérifier si c'est une erreur de quota\nif (error.message && error.message.includes('quota')) {\n return {\n error: true,\n quotaError: true,\n message: \"Quota d'API Google Calendar dépassé. Réessayez plus tard.\",\n originalError: error.message,\n statusCode: 429\n };\n}\n\n// Erreur générique\nreturn {\n error: true,\n message: \"Erreur lors de la création de l'événement: \" + error.message,\n originalError: error.message,\n statusCode: 500\n};" }, "id": "analyze-error", "name": "Analyse de l'erreur", "type": "n8n-nodes-base.code", "typeVersion": 1, "position": [ 2250, 500 ] }, { "parameters": { "respondWith": "json", "responseBody": "={{ $json }}", "options": { "responseCode": "={{ $json.statusCode || 500 }}" } }, "id": "respond-creation-error", "name": "Répondre - Erreur création", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1, "position": [ 2450, 500 ] }, { "parameters": { "conditions": { "boolean": [ { "value1": "={{ $json.authError === true }}", "value2": true } ] } }, "id": "check-auth-error", "name": "Vérification erreur auth", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [ 2250, 700 ] }, { "parameters": { "functionCode": "// Cette fonction simule le rafraîchissement du token OAuth\n// Dans un environnement de production, implémentez la logique réelle de rafraîchissement\n\n// Journaliser la tentative de rafraîchissement\nconsole.log('Tentative de rafraîchissement du token OAuth pour Google Calendar');\n\n// Simuler un délai pour le rafraîchissement\nawait new Promise(resolve => setTimeout(resolve, 1000));\n\n// Retourner un statut de rafraîchissement\nreturn {\n tokenRefreshed: true,\n message: \"Token OAuth rafraîchi avec succès. Réessayez l'opération.\"\n};" }, "id": "refresh-oauth-token", "name": "Rafraîchissement du token OAuth", "type": "n8n-nodes-base.function", "typeVersion": 1, "position": [ 2450, 700 ] }, { "parameters": { "respondWith": "json", "responseBody": "={\n \"success\": true,\n \"event\": $json,\n \"message\": \"Événement créé avec succès\"\n}", "options": {} }, "id": "respond-success", "name": "Répondre - Succès", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1, "position": [ 2250, 900 ] } ], "connections": { "webhook-trigger": { "main": [ [ { "node": "validate-format-data", "type": "main", "index": 0 } ] ] }, "validate-format-data": { "main": [ [ { "node": "check-validation-errors", "type": "main", "index": 0 } ] ] }, "check-validation-errors": { "main": [ [ { "node": "respond-validation-error", "type": "main", "index": 0 } ], [ { "node": "check-calendar-exists", "type": "main", "index": 0 } ] ] }, "check-calendar-exists": { "main": [ [ { "node": "check-calendar-error", "type": "main", "index": 0 } ] ] }, "check-calendar-error": { "main": [ [ { "node": "respond-calendar-error", "type": "main", "index": 0 } ], [ { "node": "check-availability", "type": "main", "index": 0 } ] ] }, "check-availability": { "main": [ [ { "node": "analyze-conflicts", "type": "main", "index": 0 } ] ] }, "analyze-conflicts": { "main": [ [ { "node": "check-conflicts", "type": "main", "index": 0 } ] ] }, "check-conflicts": { "main": [ [ { "node": "respond-conflict", "type": "main", "index": 0 } ], [ { "node": "create-event", "type": "main", "index": 0 } ] ] }, "create-event": { "main": [ [ { "node": "check-creation-error", "type": "main", "index": 0 } ] ] }, "check-creation-error": { "main": [ [ { "node": "analyze-error", "type": "main", "index": 0 } ], [ { "node": "respond-success", "type": "main", "index": 0 } ] ] }, "analyze-error": { "main": [ [ { "node": "check-auth-error", "type": "main", "index": 0 } ] ] }, "check-auth-error": { "main": [ [ { "node": "refresh-oauth-token", "type": "main", "index": 0 } ], [ { "node": "respond-creation-error", "type": "main", "index": 0 } ] ] }, "refresh-oauth-token": { "main": [ [ { "node": "respond-creation-error", "type": "main", "index": 0 } ] ] } }, "active": false, "settings": { "executionOrder": "v1", "saveManualExecutions": true, "callerPolicy": "workflowsFromSameOwner", "errorWorkflow": "", "saveDataErrorExecution": "all", "saveDataSuccessExecution": "all", "saveExecutionProgress": true }, "tags": ["template", "calendar", "event-creation"], "pinData": {}, "versionId": "1", "meta": { "templateCreatedBy": "MCP n8n Server", "templateDescription": "Workflow pour créer des événements dans Google Calendar avec validation des entrées et gestion des erreurs.", "templateName": "Création d'événements Google Calendar", "templateCategory": "calendar", "templateVersion": "1.0.0", "templateDocumentation": "Ce template permet de créer des événements dans Google Calendar avec une validation complète des entrées, vérification des conflits, et gestion robuste des erreurs. Il expose un webhook qui peut être facilement intégré avec une application NextJS." } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lowprofix/n8n-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server