Hello, I think it would take me days to try by myself so I’d rather ask this question here. I’m trying to use an AI Agent node to assign labels to Gmail messages. But it seems that the label has to be present already and the tool can only pass the label ID for that. Maybe that’s why I keep getting the error “Invalid Argument”
I tried connecting a tool for creating labels, but it only accepts one parameter which I have to assign manually, but I want the agent to pass the appropriate parameter. To make things even more complicated, I have 4 Gmail accounts that I want the same workflow to act on, plus one self-hosted mail account where I don’t know if it supports labels in a similar way.
I thought this would be a rather simple task, but it doesn’t seem so.
Hi MaximHH! You’re right that Gmail labels need to exist before they can be applied via the API. For your AI agent workflow, you’ll need to create a two-step process: first use a “Get All Labels” Gmail node to fetch existing labels and their IDs, then create a tool that allows your AI agent to both create new labels (using the Gmail “Create Label” operation) AND apply existing ones by ID.
For multiple Gmail accounts, you can either:
• Create separate workflows for each account with different Gmail credentials
• Use a single workflow with a Switch node that routes to different Gmail operations based on the account
Check out this existing [n8n.io]( Auto-label incoming Gmail messages with AI nodes | n8n workflow template ) workflow template that shows how to auto-label Gmail messages with AI - it handles the label creation/application logic you need. The key is giving your AI agent access to both label creation and application tools, plus the current list of existing labels to work with.