How to handle GMail variable and conditional attachments?

Describe the issue/error/question

For the Gmail node to reply to a message, is there any way to make the attachments variable and conditional? For example, the data being passed in sometimes has binary data in field attachment_0 , and sometimes there’s binary data in field attachment_0 and attachment_1 , while most of the time there’s no binary data. Right now it seems like it needs to be hardcoded in and it complains if there’s no data in those fields

Information on your n8n setup

  • n8n version: 0.209.0
  • Database you’re using (default: SQLite): SQLite
  • Running n8n with the execution process [own(default), main]:
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: Docker

Welcome to the community @axs! First would be great if you could change your username. If people come for help, the least we (or at least I) expect is that people use their name, or at least make one up instead of using ours.

To answer your question.

Currently it is not possible to say to sometimes send attachments and sometimes not. So you would have to have an IF-Node in front of it with an expression like this:

{{ Object.keys($input.item.binary).length }}

It will return the number of attachments. So you can then route the ones without attachments to a Gmail node without attachments and anything that has a number that is higher than 0 to one that has attachments defined under “Options”.

On the node that has attachments you can then use the following expression:

{{ Object.keys($input.item.binary).join(',') }}

It will then automatically fill the field with a comma-separated list of all the binary properties.

Thanks so much, that worked! Apologies for the username, I have changed it to something more personal :blush:

1 Like

Thanks a lot!

Great to hear that it helped. Have fun!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.