Factures PDF Gmail vers Google Drive et Sheets

Intermédiaire

Ceci est uncontenant 12 nœuds.Utilise principalement des nœuds comme If, Gmail, Filter, GoogleDrive, GmailTrigger. Téléchargement automatique des factures PDF de Gmail vers Google Drive et enregistrement dans une feuille de calcul

Prérequis
  • Compte Google et informations d'identification Gmail API
  • Informations d'identification Google Drive API
  • Informations d'identification Google Sheets API

Catégorie

-
Aperçu du workflow
Visualisation des connexions entre les nœuds, avec support du zoom et du déplacement
Exporter le workflow
Copiez la configuration JSON suivante dans n8n pour importer et utiliser ce workflow
{
  "id": "OOH6DNGDDDuKrcjk",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Gmail Invoice PDF to Google Drive and Sheets",
  "tags": [],
  "nodes": [
    {
      "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        224,
        304
      ],
      "parameters": {
        "simple": false,
        "filters": {
          "sender": [],
          "labelIds": [
            "CATEGORY_PERSONAL"
          ],
          "readStatus": "unread"
        },
        "options": {
          "downloadAttachments": true
        },
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "note1-2345-6789-abcd-ef1234567891",
      "name": "Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        128,
        80
      ],
      "parameters": {
        "color": 5,
        "width": 280,
        "height": 216,
        "content": "## 📧 Gmail Trigger\nThis node monitors your Gmail inbox for new emails containing invoices. It checks every minute for unread emails with 'invoice' in the subject line and downloads any PDF attachments.\n\n**Configure:** Connect your Gmail account credentials"
      },
      "typeVersion": 1
    },
    {
      "id": "filter-node-123-456-789-abcdef123456",
      "name": "A des pièces jointes PDF ?",
      "type": "n8n-nodes-base.filter",
      "position": [
        448,
        304
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "cond123",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ Object.keys($binary ?? {}).length }}",
              "rightValue": 0
            },
            {
              "id": "45eb8d9f-575d-4920-b236-2ea5be8ade19",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "note2-3456-7890-bcde-f12345678902",
      "name": "Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        432,
        480
      ],
      "parameters": {
        "color": 3,
        "width": 260,
        "height": 140,
        "content": "## 🔍 Filter Check\nThis filter ensures we only process emails that actually have attachments (PDFs). Emails without attachments are filtered out."
      },
      "typeVersion": 1
    },
    {
      "id": "gdrive-upload-123-456-789-abcdef654321",
      "name": "Téléverser vers Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        896,
        304
      ],
      "parameters": {
        "name": "={{ $json.filename || 'invoice_' + $now.toFormat('yyyyMMdd_HHmmss') + '.pdf' }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "root",
          "cachedResultName": "/ (Root folder)"
        },
        "inputDataFieldName": "=attachment_0"
      },
      "typeVersion": 3
    },
    {
      "id": "note3-4567-8901-cdef-234567890123",
      "name": "Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        864,
        80
      ],
      "parameters": {
        "color": 4,
        "width": 300,
        "height": 180,
        "content": "## 📁 Google Drive Upload\nEach PDF attachment is uploaded to your Google Drive. Files are named using the original filename or a timestamp if not available.\n\n**Configure:** \n- Connect Google Drive credentials\n- Optionally specify a folder ID instead of 'root'"
      },
      "typeVersion": 1
    },
    {
      "id": "gsheets-append-123-456-789-fedcba098765",
      "name": "Enregistrer dans Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1120,
        304
      ],
      "parameters": {
        "columns": {
          "value": {
            "name": "={{ $json.name }}"
          },
          "schema": [
            {
              "id": "kind",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "kind",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "id",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "mimeType",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "mimeType",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "starred",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "starred",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "trashed",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "trashed",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "explicitlyTrashed",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "explicitlyTrashed",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "parents",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "parents",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "spaces",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "spaces",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "version",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "version",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "webContentLink",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "webContentLink",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "webViewLink",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "webViewLink",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "iconLink",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "iconLink",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "hasThumbnail",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "hasThumbnail",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "thumbnailVersion",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "thumbnailVersion",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "viewedByMe",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "viewedByMe",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "createdTime",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "createdTime",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "modifiedTime",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "modifiedTime",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "modifiedByMeTime",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "modifiedByMeTime",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "modifiedByMe",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "modifiedByMe",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "owners",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "owners",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "lastModifyingUser",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "lastModifyingUser",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "shared",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "shared",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "ownedByMe",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "ownedByMe",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "downloadRestrictions",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "downloadRestrictions",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "capabilities",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "capabilities",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "viewersCanCopyContent",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "viewersCanCopyContent",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "copyRequiresWriterPermission",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "copyRequiresWriterPermission",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "writersCanShare",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "writersCanShare",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "permissions",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "permissions",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "permissionIds",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "permissionIds",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "originalFilename",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "originalFilename",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "fullFileExtension",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "fullFileExtension",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "fileExtension",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "fileExtension",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "md5Checksum",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "md5Checksum",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "sha1Checksum",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "sha1Checksum",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "sha256Checksum",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "sha256Checksum",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "size",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "size",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "quotaBytesUsed",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "quotaBytesUsed",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "headRevisionId",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "headRevisionId",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "isAppAuthorized",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "isAppAuthorized",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "linkShareMetadata",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "linkShareMetadata",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "inheritedPermissionsDisabled",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "inheritedPermissionsDisabled",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "autoMapInputData",
          "matchingColumns": [
            "id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": ""
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "note4-5678-9012-def0-345678901234",
      "name": "Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        896,
        496
      ],
      "parameters": {
        "color": 6,
        "width": 320,
        "height": 240,
        "content": "## 📊 Google Sheets Logging\nRecords invoice details in a spreadsheet including:\n- Date/time received\n- Sender email\n- Subject line\n- PDF filename\n- Google Drive link\n- File and Email IDs\n\n**Configure:**\n- Connect Google Sheets credentials\n- Add your spreadsheet ID\n- Ensure sheet has headers matching the column names"
      },
      "typeVersion": 1
    },
    {
      "id": "gmail-mark-read-123-456-789-0987654321ab",
      "name": "Marquer l'email comme lu",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1344,
        304
      ],
      "webhookId": "4e776efa-c75c-428c-aad3-a959fa6fe667",
      "parameters": {
        "messageId": "={{ $('Gmail Trigger').item.json.id }}",
        "operation": "markAsRead"
      },
      "typeVersion": 2.1
    },
    {
      "id": "note5-6789-0123-ef01-456789012345",
      "name": "Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1376,
        112
      ],
      "parameters": {
        "color": 2,
        "width": 280,
        "content": "## ✅ Mark as Processed\nAfter successfully uploading the PDF and logging to sheets, the original email is marked as read so it won't be processed again.\n\n**Note:** Uses same Gmail credentials as trigger"
      },
      "typeVersion": 1
    },
    {
      "id": "note6-7890-1234-f012-567890123456",
      "name": "Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -272,
        336
      ],
      "parameters": {
        "width": 400,
        "height": 424,
        "content": "## 🚀 Setup Instructions\n\n1. **Gmail OAuth2**: Connect your Gmail account in all Gmail nodes\n2. **Google Drive OAuth2**: Connect your Google Drive account\n3. **Google Sheets OAuth2**: Connect your Google Sheets account\n4. **Spreadsheet Setup**: \n   - Create a Google Sheet\n   - Add headers: Date, Sender, Subject, Filename, Drive_Link, File_ID, Email_ID\n   - Copy the spreadsheet ID from the URL\n   - Paste it in the Google Sheets node\n5. **Optional**: Change the Drive folder from 'root' to a specific folder ID\n6. **Test**: Send yourself an email with 'invoice' in subject and a PDF attached"
      },
      "typeVersion": 1
    },
    {
      "id": "5f57d83d-03a6-4729-aa66-a8ad05d946d6",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        672,
        304
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "f8e67ccc-5871-4413-ad2a-57849477c0d8",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $binary && Object.keys($binary).length > 0 }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "timezone": "America/New_York",
    "errorWorkflow": "",
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "saveExecutionProgress": true,
    "saveDataErrorExecution": "all",
    "saveDataSuccessExecution": "all"
  },
  "connections": {
    "5f57d83d-03a6-4729-aa66-a8ad05d946d6": {
      "main": [
        [
          {
            "node": "gdrive-upload-123-456-789-abcdef654321",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "a1b2c3d4-e5f6-7890-abcd-ef1234567890": {
      "main": [
        [
          {
            "node": "filter-node-123-456-789-abcdef123456",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "filter-node-123-456-789-abcdef123456": {
      "main": [
        [
          {
            "node": "5f57d83d-03a6-4729-aa66-a8ad05d946d6",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "gsheets-append-123-456-789-fedcba098765": {
      "main": [
        [
          {
            "node": "gmail-mark-read-123-456-789-0987654321ab",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "gdrive-upload-123-456-789-abcdef654321": {
      "main": [
        [
          {
            "node": "gsheets-append-123-456-789-fedcba098765",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Foire aux questions

Comment utiliser ce workflow ?

Copiez le code de configuration JSON ci-dessus, créez un nouveau workflow dans votre instance n8n et sélectionnez "Importer depuis le JSON", collez la configuration et modifiez les paramètres d'authentification selon vos besoins.

Dans quelles scénarios ce workflow est-il adapté ?

Intermédiaire

Est-ce payant ?

Ce workflow est entièrement gratuit et peut être utilisé directement. Veuillez noter que les services tiers utilisés dans le workflow (comme l'API OpenAI) peuvent nécessiter un paiement de votre part.

Informations sur le workflow
Niveau de difficulté
Intermédiaire
Nombre de nœuds12
Catégorie-
Types de nœuds7
Description de la difficulté

Adapté aux utilisateurs expérimentés, avec des workflows de complexité moyenne contenant 6-15 nœuds

Liens externes
Voir sur n8n.io

Partager ce workflow

Catégories

Catégories: 34