Send document as pdf using Gmail

Hello,

I’m new here and also as an n8n user. Congratulations to the team for what they’ve built so far.

I want to send a document that is on Google Drive as a pdf using Gmail, I tried to use Drive’s download node, but I wasn’t successful. I’m using n8n with the npx command.

Displays ERROR: Forbidden - perhaps check your credentials?

Request failed with status code 403

{"message":"Request failed with status code 403","name":"Error","stack":"Error: Request failed with status code 403\n    at createError (C:\\Users\\Samsung\\AppData\\Roaming\\npm\\node_modules\\n8n\\node_modules\\axios\\lib\\core\\createError.js:16:15)\n    at settle (C:\\Users\\Samsung\\AppData\\Roaming\\npm\\node_modules\\n8n\\node_modules\\axios\\lib\\core\\settle.js:17:12)\n    at IncomingMessage.handleStreamEnd (C:\\Users\\Samsung\\AppData\\Roaming\\npm\\node_modules\\n8n\\node_modules\\axios\\lib\\adapters\\http.js:269:11)\n    at IncomingMessage.emit (node:events:402:35)\n    at endReadableNT (node:internal/streams/readable:1343:12)\n    at processTicksAndRejections (node:internal/process/task_queues:83:21)"}

This is my workflow

{
  "name": "Criar documento do template",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        -480,
        -450
      ],
      "disabled": true
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "copy",
        "fileId": "={{$node[\"Atualizar template\"].json[\"documentId\"]}}",
        "options": {
          "name": "={{$node[\"Buscar registro\"].json[\"Nome\"]}}",
          "parents": []
        }
      },
      "name": "Gerar pdf",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 1,
      "position": [
        360,
        -450
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "8",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "update",
        "documentURL": "1zV0Dyhw_I2s6aGSph6GDS7o70zMrwN9F3-D9m3byiWo",
        "actionsUi": {
          "actionFields": [
            {
              "action": "insert",
              "locationChoice": "location",
              "text": "=NOME: {{$json[\"Nome\"]}}\nEMAIL: {{$json[\"Email\"]}}"
            }
          ]
        }
      },
      "name": "Atualizar template",
      "type": "n8n-nodes-base.googleDocs",
      "typeVersion": 1,
      "position": [
        -50,
        -450
      ],
      "credentials": {
        "googleDocsOAuth2Api": {
          "id": "11",
          "name": "Google Docs account"
        }
      }
    },
    {
      "parameters": {
        "resource": "message",
        "subject": "Orcamento",
        "message": "=Ola {{$node[\"Buscar registro\"].json[\"Nome\"]}}",
        "toList": [
          "={{$node[\"Buscar registro\"].json[\"Email\"]}}"
        ],
        "additionalFields": {
          "attachmentsUi": {
            "attachmentsBinary": [
              {
                "property": "=data"
              }
            ]
          }
        }
      },
      "name": "Enviar email com pdf",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 1,
      "position": [
        800,
        -450
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "7",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "sheetId": "1b5FKN2Cs6JXLEtj4jBpH7E19N-4YnoYPljaiKTp4Rzo",
        "options": {}
      },
      "name": "Buscar registro",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        -260,
        -450
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "6",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "share",
        "fileId": "={{$json[\"documentId\"]}}",
        "permissionsUi": {
          "permissionsValues": {
            "role": "writer",
            "type": "anyone"
          }
        },
        "options": {}
      },
      "name": "Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 1,
      "position": [
        160,
        -450
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "8",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "download",
        "fileId": "={{$json[\"id\"]}}",
        "options": {}
      },
      "name": "Upload",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 1,
      "position": [
        560,
        -450
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "8",
          "name": "Google Drive account"
        }
      }
    }
  ],
  "connections": {
    "Gerar pdf": {
      "main": [
        [
          {
            "node": "Upload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Atualizar template": {
      "main": [
        [
          {
            "node": "Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Buscar registro": {
      "main": [
        [
          {
            "node": "Atualizar template",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start": {
      "main": [
        [
          {
            "node": "Buscar registro",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Drive": {
      "main": [
        [
          {
            "node": "Gerar pdf",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload": {
      "main": [
        [
          {
            "node": "Enviar email com pdf",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "id": 13
}

Could you help me with this?

Thanks,

Claudio Balbino

Hi @Claudio_Balbino, welcome to the community and thanks so much for reaching out!

A 403 status would indicate a permissions problem as per Google’s docs, which includes rate limiting problems. Is your initial Google Sheets node returning multiple items and do individual operations work using your Google Drive credentials (e.g. if you run a simple workflow consisting of one node downloading one file, would this work for you)?

If so, you might have hit this Google Drive API write limit:

The rate of Drive API write requests is limited—avoid exceeding 3 requests per second of sustained write or insert requests, per account. Note: This rate limit can’t be increased.

Hi @MutedJam

I’m not sure I understand correctly, but in this example my spreadsheet has only one line… to test I eliminated some node from the drive and the problem persists

Is it related to me using npx locally?

{"message":"Request failed with status code 403","name":"Error","stack":"Error: Request failed with status code 403\n    at createError (C:\\Users\\Samsung\\AppData\\Roaming\\npm\\node_modules\\n8n\\node_modules\\axios\\lib\\core\\createError.js:16:15)\n    at settle (C:\\Users\\Samsung\\AppData\\Roaming\\npm\\node_modules\\n8n\\node_modules\\axios\\lib\\core\\settle.js:17:12)\n    at IncomingMessage.handleStreamEnd (C:\\Users\\Samsung\\AppData\\Roaming\\npm\\node_modules\\n8n\\node_modules\\axios\\lib\\adapters\\http.js:269:11)\n    at IncomingMessage.emit (node:events:402:35)\n    at endReadableNT (node:internal/streams/readable:1343:12)\n    at processTicksAndRejections (node:internal/process/task_queues:83:21)"}

Do you have access to the drive/folder, you are trying to upload data to?

I would isolate the drive node and upload a file to a folder before adding it to any workflow. That way, you discard any issues related to permissions/credentials.

Thanks a lot for confirming @Claudio_Balbino and for chipping in @RicardoE105!

I quickly tried this on my end using npx and could indeed reproduce the problem when trying to download a Google Docs file. Even with a simple workflow like this:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "download",
        "fileId": "1NImpwGUackjZVVbU460Dn1Lr1L_52QM_SVAt3xJUwzw",
        "options": {}
      },
      "name": "Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 1,
      "position": [
        450,
        300
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "4",
          "name": "Google Drive account"
        }
      }
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

This is working fine for other file types though, the only difference would be the File Id in this case:

Could this be because Google does not allow downloading Google Docs files directly (only in converted formats like MS Word) @RicardoE105? As per this doc:

Note: The only way to download a Google Workspace file is to export and download the file in a different file format.

@MutedJam

How do i transform this google docs into pdf to use the downlod node?

As @MutedJam explained, looks like for Google native files you need to export to a different mime-type in order to ‘download’ the file.

Right now, Google drive api does not support content downloading for native google drive files (google docs, sheets etc.), so you cant download content (current or of an old revision), you can only export it to a different mime type.

We need to add the export functionality to the node.

1 Like

I am afraid that’s an operation not currently supported by the Google Drive node.

In case it doesn’t have to be the specific Google Docs file you want to create the PDF file from, you could alternatively use a specialized service to create PDFs. For example Anvil (which you could connect to using our HTTP Request node) or APITemplate.io (which has its own node).

These services essentially create PDF documents for you based on the payload they receive.

Got added. We will let you know when it’s released.

3 Likes

@MutedJam and @RicardoE105

Thank you very much for your quick feedback and attention.

While we don’t have a solution with Google, I’m using the APITemplate

1 Like

Glad to hear this approach is working out for you for now!

I have also tested the enhanced Google Drive node developed by @RicardoE105 already and it’s working great with Google Docs files (including exporting them as PDF). So not much longer before your original approach would work too :slight_smile:

Many thanks for bringing this up!

2 Likes

what good news! :partying_face: :rocket:

@MutedJam and @RicardoE105, Hey! Now I’m looking for a solution to download Google Documents in pdf format. Tell me, is this already deployed in the latest version? I have upgraded to version 0.147.1 and am getting the following error:

Perhaps I am configuring something incorrectly in the node properties?

It does not work because it has not been merged yet. We will notify here when we do.

1 Like

@RicardoE105 , thanks!

@RicardoE105, Hey! Any news on this feature (exporting files to other formats in the Google Drive node)?

It’s still in the review column. Let me try to move it forward internally.

2 Likes

@RicardoE105 , Hey!
Is there a timeline for the implementation of this functionality? This can be very important for my project). Thanks in advance for your feedback!