Gmail trigger - 2 mails at the same time - looping issue

Hi everyone,
I am facing an issue with a workflow involving email parsing.

Issue description

I am polling Gmail every minute to get new email and parse them using a function node.
The only issue is that sometimes I get several emails within the minute I last parsed.
For exemple :

  • Email n°1 : Received at 14:05:10
  • Email n°2 : Received at 14:05:45

I am seeing the two items in my trigger so no issue on this end but when I am going through my function node, my code seems to be running only on the first item.

Being aware that a function node only run once (vs. other nodes that run several times), I encapsuled all my code into a loop that should parse all my items.

for (item of items) {
//my code here
// some HTML parsing
item.json.key1 = value1
item.json.key2 = value2
item.json.key3 = value3
item.json.key4 = value4
}
return items

Except that my code runs only for the first item & the second items is the initial email object.

Here is what the current output looks like

[
{
"key1": "value1",
"key2": "value2",
"key3": "value3",
"key4": "value4"
// this is obtained through my code
},
{
"id": "XX",
"threadId": "XX",
"labelIds": [
"UNREAD",
"CATEGORY_FORUMS",
"INBOX"
]
// this is the 2nd email which is not formatted as I want

My set-up

  • n8n version: [email protected]
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: Cloud

Is there something I have done wrong ? Should I use the Split in Batches node ?

Thanks for the help :pray:

Hey @Mathieu_Brun-Picard,
from what I can see this looks good. Can you share your workflow so that we can take a deeper look?

Hey @marcus ,
Here is a screenshot of the workflow.

The trigger is another workflow that enrolls this second parsing workflow.
Trigger Workflow :

Parsing Workflow

Let me know if you need anything else.

The Execute Workflow node will ony be executed once but it will be executed with all input items so 2 gmail trigger events should NOT be a problem here. From the screenshots I don’t see a problem why it shouldn’t work, but I can only guess.

To debug your workflow you could use our data pinning feature with your Gmail Trigger node to simulate two events going through your workflow. Did you try out a workflow without executing subworkflows to see at what point it fails for more than one event?

@marcus Thanks for the suggestion !

I haven’t succeeded in pinning 2 events going through with the trigger but I am going to use a function nodes that outputs an array with 2 elements to check how it goes.

Regarding your second questions, my executions fails at the first node (Extract Contact Info) as only one item is processed by the function where I would expect all of the items to be processed

Edit: trying the process described above my function parse the content without any problem but when replaying the executions I am encountering bugs again :thinking: I’m kind of stuck