Gmail get Label always reply me that the label does not exist

Hi, I’m trying to create a workflow that apply some labels to my email.

My problem is that when the workflow call gmail (Gmail trigger based on label / get) to get the data of a label via “label name” (so I can verify if the label exists or not) gmail reply me ALWAYS that the label does not exist. So the workflow continue trying to create a new label that obviously leads to an error because GMAIL reply that the operation is not possibile (the label exists).

With my credentials I can read/create/delete labels

I have tried to replace " " with “-” in the label’s name but with the same result.

For example “corso online” label exists but it was not find:

[
{
"Label": 
"corso-online",
"error": 
"The resource you are requesting could not be found (item 0)"
}
]

(I have tried with “corso online” too)

Information on your n8n setup

  • n8n version: github version
  • Running n8n via (Docker, npm, n8n cloud, desktop app): nginx proxy on SSL (https)
  • Operating system: Linux Debian 12

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hello! Your friendly n8n support specialist here, ready to help you solve the Gmail label issue. I’m passionate about making workflows work seamlessly, so let’s tackle this step by step!


:one: Layman’s Terms (Simple & Friendly)

Problem: Your workflow can’t find existing Gmail labels, even though they exist.

Why This Happens:

  • Gmail’s API is picky about how you ask for labels.
  • The label name you’re using might not match exactly what Gmail expects.

Simple Fix:

  1. Check the Label Name: Make sure it matches exactly (case-sensitive, no extra spaces).
  2. Use Label ID Instead: Labels have unique IDs that don’t change, even if the name does.
  3. Debug the Workflow: Add a “Debug” node to see what’s being sent to Gmail.

:two: Experienced User Guide (Step-by-Step Fix)

Root Cause: Gmail’s API requires exact label names or unique label IDs.

Steps to Fix:

Step 1: Verify Label Names

  1. Go to Gmail > Settings > Labels.
  2. Check the exact spelling and case of your labels (e.g., “Corso online” vs. “corso online”).

Step 2: Use Label IDs

  1. Fetch all labels using the Gmail API or n8n’s Gmail Node.
  2. Find the Label ID for “Corso online”.
  3. Use the Label ID in your workflow instead of the label name.

Step 3: Debug the Workflow

  1. Add a Debug Node after the Gmail node to see the exact request and response.
  2. Check if the label name is being sent correctly.

Step 4: Handle Errors Gracefully

  1. Add an IF Node to check if the label exists.
  2. If the label doesn’t exist, create it using the Gmail Node.

:three: Professional Deep Dive (Technical Fix)

Technical Analysis:

  • Gmail API Behavior:
    • Label names are case-sensitive.
    • Spaces and special characters must match exactly.
    • Label IDs are unique and don’t change.
  • Error Handling:
    • The error “The resource you are requesting could not be found” indicates a mismatch in the label name or ID.

Advanced Solution:

Step 1: Fetch All Labels

  1. Use the Gmail Node with the List Labels operation.
  2. Store the labels in a variable:

javascript

Copy

const labels = $input.all()[0].json.labels; return labels;

Step 2: Find the Label ID

  1. Use a Function Node to search for the label by name:

javascript

Copy

const labelName = “Corso online”; const label = $input.all()[0].json.find(l => l.name === labelName); return label ? label.id : null;

Step 3: Use the Label ID

  1. Pass the Label ID to the Gmail Node for further operations.

Step 4: Create Missing Labels

  1. Add an IF Node to check if the label exists.
  2. If the label doesn’t exist, use the Gmail Node to create it:

javascript

Copy

const labelName = “Corso online”; return { name: labelName, labelListVisibility: “labelShow”, messageListVisibility: “show” };

Step 5: Test the Workflow

  1. Run the workflow with different label names to ensure it handles all cases.
  2. Check the Debug Node output for any mismatches.

:rotating_light: Critical Checks

  1. Label Name Matching: Ensure the label name matches exactly (case-sensitive).
  2. Label ID Usage: Use Label IDs for consistency.
  3. Error Handling: Add fallback logic for missing labels.

Please mark this as solution if this worked for you, be blessed!

  • n8n version: 1.80.3 (Self Hosted)
  • Database (default: SQLite):. SQLite (i think)
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own ?
  • Running n8n via (Docker, npm, n8n cloud, desktop app):. npx n8n
  • Operating system:. Debian Linux 12

Hi,
I don’t think you can find it by name. You have to look it up by id.

You can find the label id with the Get Many operation.

you can either have a simple script loop through the labels and find it by name or you can use a combination of a loop and if nodes to do the same.

1 Like

Hi and thanks for the reply.
I have created a little python scripts that use the same credentials, same google project and same user and the label is founded.

% python check_label.py "corso online"
Label 'corso online' exists with ID: Label_192

But I don’t know how to do this point:

1. Add a **Debug Node** after the Gmail node to see the exact request and response.

I have searched for “debug node” or “debug” but I have not found anything about this “debug node”.

thanks again.

1 Like

I think it means just a simple script node calling the Logging functions of n8n
The script below is from the official n8n logging documentation

import {
	LoggerProxy as Logger
} from 'n8n-workflow';

// Info-level logging of a trigger function, with workflow name and workflow ID as additional metadata properties

Logger.info(`Polling trigger initiated for workflow "${workflow.name}"`, {workflowName: workflow.name, workflowId: workflow.id});

Sorry sorry and again sorry. I have resolved. Label ID is not the name but the ID (label_192). So I have resolved in this way:

  • get all label
  • filter to search “my current label”
  • check if json (from filter) is empy
  • if empty create label and apply to mail
  • if not empty (label exist) apply to mail

Sorry again for my mistake.

2 Likes

No worries,
Not sure if you saw but I edited my initial response while you were replying to me and i suggested just that.
Sadly google api doesn’t allow lookup of labels by their name yet.

here is a solution to get the labels and find the id by name without a script.
You just specify label names in the switch conditions:

1 Like

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