Getting undefined items after multiple loop nodes with multiple branches within them

Describe the problem/error/question

I am getting undefined items later on in my workflow. This happens within a loop node that is inside another loop node. The inside loop also has branches. I have a suspicion that the large number of branches I have causes the issue, but I also tried referencing a node that doesn’t have branches (Get Transcription) and the issue still occured.

Below are some things I’ve tried:

-Checked and tried this thread Items losing reference of previous nodes
-And this one Node variable showed undefined on execution for HTTP Request when connected to a Item Lists node - #6 by engowen

I tried these syntaxes:
// Instead of this (which may be undefined):
{{ $(‘Node’).item.json.data }}

// Use this to always get the first item:
{{ $(‘Node’).first().json.data }}

// Or use this to get all items and select by index:
{{ $(‘Node’).all()[0].json.data }}

What is the error message (if any)?

[undefined]

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

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

You cannot use nested loops.
Complete the first loop before starting the second loop.
The “Done” output of the loop node includes all the results from that loop.

But I need to loop through items in an array, and each of those items are IDs to another array. So how do I “loop” through both of those?

Could be done somehow like this:

It’s important to finish the first loop before starting a new loop.
Maybe you can pin the data to the nodes, or share some mock data (responses of the HTTP nodes). This makes it easier to give hints to your workflow.

Get conversation:

{
  "nodes": [
    {
      "parameters": {
        "url": "=https://services.leadconnectorhq.com/conversations/{{ $json.id }}",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "highLevelOAuth2Api",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "Bearer 123"
            },
            {
              "name": "Version",
              "value": "2021-04-15"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1500,
        20
      ],
      "id": "e570920d-df8b-4dfd-83f6-22145a53b209",
      "name": "Get Conversation",
      "credentials": {
        "highLevelOAuth2Api": {
          "id": "kAJW4QUxPv6ZKfuV",
          "name": "Homezone"
        }
      }
    }
  ],
  "connections": {
    "Get Conversation": {
      "main": [
        []
      ]
    }
  },
  "pinData": {
    "Get Conversation": [
      {
        "locationId": "SXzmY6HCrn4NO3NdbMeh",
        "contactId": "FUkRqGV0rv9CgCN3L7Tc",
        "unreadCount": 1,
        "type": 1,
        "deleted": false,
        "id": "UdLPZYXXkneSTa3m7IdZ",
        "isLastMessageInternalComment": false,
        "lastMessageType": 1,
        "lastMessageDate": {
          "seconds": 1751334500,
          "nanoseconds": 369000000
        },
        "lastMessageDirection": "inbound",
        "traceId": "33571913-b44f-45ac-b261-7d1d5ee91018"
      }
    ]
  },
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "50931bed8c10aeb35daa254f0f636a01b5c3295abf4440884db4e4d516ff68f4"
  }
}

Get messages:

{
“nodes”: [
{
“parameters”: {
“url”: “=https://services.leadconnectorhq.com/conversations/{{ $json.id }}/messages”,
“authentication”: “predefinedCredentialType”,
“nodeCredentialType”: “highLevelOAuth2Api”,
“sendQuery”: true,
“queryParameters”: {
“parameters”: [
{
“name”: “type”,
“value”: “TYPE_CALL”
}
]
},
“sendHeaders”: true,
“headerParameters”: {
“parameters”: [
{
“name”: “Accept”,
“value”: “application/json”
},
{
“name”: “Authorization”,
“value”: “Bearer 123”
},
{
“name”: “Version”,
“value”: “2021-04-15”
}
]
},
“options”: {}
},
“type”: “n8n-nodes-base.httpRequest”,
“typeVersion”: 4.2,
“position”: [
1820,
100
],
“id”: “3417035d-5788-4e31-941a-bc0f562dd729”,
“name”: “Get Messages”,
“credentials”: {
“highLevelOAuth2Api”: {
“id”: “kAJW4QUxPv6ZKfuV”,
“name”: “Homezone”
}
}
}
],
“connections”: {
“Get Messages”: {
“main”: [

]
}
},
“pinData”: {
“Get Messages”: [
{
“messages”: {
“lastMessageId”: “nu3wY4rkZPlQOrkSC6BO”,
“nextPage”: false,
“messages”: [
{
“id”: “nu3wY4rkZPlQOrkSC6BO”,
“direction”: “inbound”,
“status”: “completed”,
“type”: 1,
“locationId”: “SXzmY6HCrn4NO3NdbMeh”,
“contactId”: “FUkRqGV0rv9CgCN3L7Tc”,
“conversationId”: “UdLPZYXXkneSTa3m7IdZ”,
“dateAdded”: “2025-07-01T01:48:20.370Z”,
“meta”: {
“call”: {
“duration”: 9,
“status”: “completed”
}
},
“altId”: “CA48daf51a63d95df2537b6fbb8af099e9”,
“messageType”: “TYPE_CALL”
}
]
},
“traceId”: “55ffd144-6f02-4e17-8bac-3a345b4bf1e2”
}
]
},
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “50931bed8c10aeb35daa254f0f636a01b5c3295abf4440884db4e4d516ff68f4”
}
}


I think that pasted a bit badly.

Here’s the json for

“Search/Filter conversations” node:

[
  {
    "conversations": [
      {
        "id": "bcfQU06JH0B5crPgRNxb",
        "locationId": "SXzmY6HCrn4NO3NdbMeh",
        "dateAdded": 1751392897115,
        "dateUpdated": 1751392897284,
        "lastMessageDate": 1751392897225,
        "lastMessageType": "TYPE_CALL",
        "lastMessageDirection": "inbound",
        "unreadCount": 1,
        "lastManualMessageDate": 1751392897225,
        "followers": [],
        "isLastMessageInternalComment": false,
        "contactId": "zsAsPuDmWeyNvI3vsYrx",
        "fullName": null,
        "contactName": "(810) 339-0140",
        "companyName": null,
        "phone": "+18103390140",
        "tags": [
          "gbp-call",
          "new-lead"
        ],
        "type": "TYPE_PHONE",
        "scoring": [],
        "attributed": null,
        "email": null,
        "sort": [
          1751392897225
        ]
      },
      {
        "id": "oK77vnSTF4sZfvyNO61e",
        "locationId": "SXzmY6HCrn4NO3NdbMeh",
        "dateAdded": 1751377540637,
        "dateUpdated": 1751377540842,
        "lastMessageDate": 1751377540785,
        "lastMessageType": "TYPE_CALL",
        "lastMessageDirection": "inbound",
        "unreadCount": 1,
        "lastManualMessageDate": 1751377540785,
        "followers": [],
        "isLastMessageInternalComment": false,
        "contactId": "XztiyjoDJ6C5TyCDXoeO",
        "fullName": null,
        "contactName": "(937) 694-8019",
        "companyName": null,
        "phone": "+19376948019",
        "tags": [
          "gbp-call",
          "new-lead"
        ],
        "type": "TYPE_PHONE",
        "scoring": [],
        "attributed": null,
        "email": null,
        "sort": [
          1751377540785
        ]
      },
      {
        "id": "UdLPZYXXkneSTa3m7IdZ",
        "locationId": "SXzmY6HCrn4NO3NdbMeh",
        "dateAdded": 1751334500268,
        "dateUpdated": 1751334500431,
        "lastMessageDate": 1751334500369,
        "lastMessageType": "TYPE_CALL",
        "lastMessageDirection": "inbound",
        "unreadCount": 1,
        "lastManualMessageDate": 1751334500369,
        "followers": [],
        "isLastMessageInternalComment": false,
        "contactId": "FUkRqGV0rv9CgCN3L7Tc",
        "fullName": null,
        "contactName": "(920) 609-3940",
        "companyName": null,
        "phone": "+19206093940",
        "tags": [
          "ppc-lp-call"
        ],
        "type": "TYPE_PHONE",
        "scoring": [],
        "attributed": true,
        "email": null,
        "sort": [
          1751334500369
        ]
      },
      {
        "id": "jLc5NiN6eMlxHoLoaYNJ",
        "locationId": "SXzmY6HCrn4NO3NdbMeh",
        "dateAdded": 1750792201051,
        "dateUpdated": 1751317569824,
        "lastMessageDate": 1751317569762,
        "lastMessageType": "TYPE_CALL",
        "lastMessageDirection": "inbound",
        "unreadCount": 4,
        "lastManualMessageDate": 1751317569762,
        "followers": [],
        "isLastMessageInternalComment": false,
        "contactId": "XjcZKq8uJ6bVL08cFA0V",
        "fullName": null,
        "contactName": "(248) 500-8389",
        "companyName": null,
        "phone": "+12485008389",
        "tags": [
          "gbp-call",
          "new-lead"
        ],
        "type": "TYPE_PHONE",
        "scoring": [],
        "attributed": null,
        "email": null,
        "sort": [
          1751317569762
        ]
      },
      {
        "id": "5Bfd3QR2VDRLHpwxIfYs",
        "locationId": "SXzmY6HCrn4NO3NdbMeh",
        "dateAdded": 1751313083735,
        "dateUpdated": 1751313083899,
        "lastMessageDate": 1751313083844,
        "lastMessageType": "TYPE_CALL",
        "lastMessageDirection": "inbound",
        "unreadCount": 1,
        "lastManualMessageDate": 1751313083843,
        "followers": [],
        "isLastMessageInternalComment": false,
        "contactId": "KtDRlygEgGxYjXJbZEjU",
        "fullName": null,
        "contactName": "(810) 259-9259",
        "companyName": null,
        "phone": "+18102599259",
        "tags": [
          "lsa-call"
        ],
        "type": "TYPE_PHONE",
        "scoring": [],
        "attributed": null,
        "email": null,
        "sort": [
          1751313083844
        ]
      },
      {
        "id": "lyekdvuAznY9pai3EkV6",
        "locationId": "SXzmY6HCrn4NO3NdbMeh",
        "dateAdded": 1751305292810,
        "dateUpdated": 1751305292981,
        "lastMessageDate": 1751305292920,
        "lastMessageType": "TYPE_CALL",
        "lastMessageDirection": "inbound",
        "unreadCount": 1,
        "lastManualMessageDate": 1751305292920,
        "followers": [],
        "isLastMessageInternalComment": false,
        "contactId": "xWF6OSDCf2bVSJCFwYGe",
        "fullName": null,
        "contactName": "(248) 993-4378",
        "companyName": null,
        "phone": "+12489934378",
        "tags": [
          "lsa-call"
        ],
        "type": "TYPE_PHONE",
        "scoring": [],
        "attributed": null,
        "email": null,
        "sort": [
          1751305292920
        ]
      },
      {
        "id": "oUvOvWnIHkl8GLIvLmPn",
        "locationId": "SXzmY6HCrn4NO3NdbMeh",
        "dateAdded": 1751304317036,
        "dateUpdated": 1751304317241,
        "lastMessageDate": 1751304317183,
        "lastMessageType": "TYPE_CALL",
        "lastMessageDirection": "inbound",
        "unreadCount": 1,
        "lastManualMessageDate": 1751304317183,
        "followers": [],
        "isLastMessageInternalComment": false,
        "contactId": "8fzgLgetG042oO6I06yM",
        "fullName": "",
        "contactName": "(855) 625-0400",
        "companyName": null,
        "phone": "+18556250400",
        "tags": [],
        "type": "TYPE_PHONE",
        "scoring": [],
        "sort": [
          1751304317183
        ]
      },
      {
        "id": "1U83dhHYFvjCfzL3oOX5",
        "locationId": "SXzmY6HCrn4NO3NdbMeh",
        "dateAdded": 1750336580790,
        "dateUpdated": 1751293594155,
        "lastMessageDate": 1751293594102,
        "lastMessageType": "TYPE_CALL",
        "lastMessageDirection": "inbound",
        "unreadCount": 2,
        "lastManualMessageDate": 1751293594102,
        "followers": [],
        "isLastMessageInternalComment": false,
        "contactId": "YHdXU0HLBwevspGqNtmL",
        "fullName": null,
        "contactName": "(810) 705-2176",
        "companyName": null,
        "phone": "+18107052176",
        "tags": [
          "gbp-call",
          "new-lead"
        ],
        "type": "TYPE_PHONE",
        "scoring": [],
        "attributed": null,
        "email": null,
        "sort": [
          1751293594102
        ]
      },
      {
        "id": "PIzEfzNQQyYSEz2rcYhy",
        "locationId": "SXzmY6HCrn4NO3NdbMeh",
        "dateAdded": 1751289673708,
        "dateUpdated": 1751289673859,
        "lastMessageDate": 1751289673806,
        "lastMessageType": "TYPE_CALL",
        "lastMessageDirection": "inbound",
        "unreadCount": 1,
        "lastManualMessageDate": 1751289673806,
        "followers": [],
        "isLastMessageInternalComment": false,
        "contactId": "3ssREAFdkkKzZl46uSVp",
        "fullName": null,
        "contactName": "(810) 919-4525",
        "companyName": null,
        "phone": "+18109194525",
        "tags": [
          "lsa-call"
        ],
        "type": "TYPE_PHONE",
        "scoring": [],
        "attributed": null,
        "email": null,
        "sort": [
          1751289673806
        ]
      },
      {
        "id": "cq4g8bsyHKXnoQGijuPp",
        "locationId": "SXzmY6HCrn4NO3NdbMeh",
        "dateAdded": 1751289476623,
        "dateUpdated": 1751289476856,
        "lastMessageDate": 1751289476778,
        "lastMessageType": "TYPE_CALL",
        "lastMessageDirection": "inbound",
        "unreadCount": 1,
        "lastManualMessageDate": 1751289476778,
        "followers": [],
        "isLastMessageInternalComment": false,
        "contactId": "drrU2gBzLRtgZSpwwRvJ",
        "fullName": "Roxanna Bass",
        "contactName": "Roxanna Bass",
        "companyName": null,
        "email": "[email protected]",
        "phone": "+15172028803",
        "tags": [
          "gbp-call",
          "new-lead"
        ],
        "type": "TYPE_PHONE",
        "scoring": [],
        "attributed": null,
        "sort": [
          1751289476778
        ]
      },
      {
        "id": "hmtnIxV1tPdBlI9UBZVu",
        "locationId": "SXzmY6HCrn4NO3NdbMeh",
        "dateAdded": 1750857958614,
        "dateUpdated": 1751289461342,
        "lastMessageDate": 1751289461290,
        "lastMessageType": "TYPE_CALL",
        "lastMessageBody": "Hi this is Homezone Windows & Roofing, I saw that we just missed your call how can I help?",
        "lastOutboundMessageAction": "manual",
        "lastMessageDirection": "inbound",
        "unreadCount": 3,
        "lastManualMessageDate": 1751289461290,
        "followers": [],
        "isLastMessageInternalComment": false,
        "contactId": "DFCw3lVnjazhCD3DOuvI",
        "fullName": null,
        "contactName": "(810) 238-3333",
        "companyName": null,
        "phone": "+18102383333",
        "tags": [
          "lsa-call",
          "gbp-call",
          "new-lead"
        ],
        "type": "TYPE_PHONE",
        "scoring": [],
        "attributed": null,
        "email": null,
        "sort": [
          1751289461290
        ]
      },
      {
        "id": "vBsyUiaGYMZWQsiw2poY",
        "locationId": "SXzmY6HCrn4NO3NdbMeh",
        "dateAdded": 1751286990002,
        "dateUpdated": 1751286990340,
        "lastMessageDate": 1751286990111,
        "lastMessageType": "TYPE_CALL",
        "lastMessageDirection": "inbound",
        "unreadCount": 1,
        "lastManualMessageDate": 1751286990111,
        "followers": [],
        "isLastMessageInternalComment": false,
        "contactId": "mfcA2AeNUwodLVjND0iU",
        "fullName": null,
        "contactName": "(989) 295-5215",
        "companyName": null,
        "phone": "+19892955215",
        "tags": [
          "lsa-call"
        ],
        "type": "TYPE_PHONE",
        "scoring": [],
        "attributed": null,
        "email": null,
        "sort": [
          1751286990111
        ]
      },
      {
        "id": "KSxg9vJR9JovkgN6GZDm",
        "locationId": "SXzmY6HCrn4NO3NdbMeh",
        "dateAdded": 1751057497153,
        "dateUpdated": 1751057497327,
        "lastMessageDate": 1751057497265,
        "lastMessageType": "TYPE_CALL",
        "lastMessageDirection": "inbound",
        "unreadCount": 1,
        "lastManualMessageDate": 1751057497265,
        "followers": [],
        "isLastMessageInternalComment": false,
        "contactId": "lIGDybGR2eMLLvMjpHQK",
        "fullName": null,
        "contactName": "(929) 480-1915",
        "companyName": null,
        "phone": "+19294801915",
        "tags": [
          "ppc-lp-call"
        ],
        "type": "TYPE_PHONE",
        "scoring": [],
        "attributed": true,
        "email": null,
        "sort": [
          1751057497265
        ]
      },
      {
        "id": "xxOQyKAGqs6lsqDaNazd",
        "locationId": "SXzmY6HCrn4NO3NdbMeh",
        "dateAdded": 1751056521807,
        "dateUpdated": 1751056521976,
        "lastMessageDate": 1751056521915,
        "lastMessageType": "TYPE_CALL",
        "lastMessageDirection": "inbound",
        "unreadCount": 1,
        "lastManualMessageDate": 1751056521915,
        "followers": [],
        "isLastMessageInternalComment": false,
        "contactId": "sXLDNTDuekb7fiJpvF3f",
        "fullName": null,
        "contactName": "(248) 842-8374",
        "companyName": null,
        "phone": "+12488428374",
        "tags": [
          "lsa-call"
        ],
        "type": "TYPE_PHONE",
        "scoring": [],
        "attributed": null,
        "email": null,
        "sort": [
          1751056521915
        ]
      },
      {
        "id": "yAySD7YP9Mm2w9cRP7SP",
        "locationId": "SXzmY6HCrn4NO3NdbMeh",
        "dateAdded": 1748547315057,
        "dateUpdated": 1751052416707,
        "lastMessageDate": 1751052416654,
        "lastMessageType": "TYPE_CALL",
        "lastMessageDirection": "inbound",
        "unreadCount": 3,
        "lastManualMessageDate": 1751052416654,
        "followers": [],
        "isLastMessageInternalComment": false,
        "contactId": "f5EOEaxMLnisy9366Wzz",
        "fullName": null,
        "contactName": "(810) 877-2530",
        "companyName": null,
        "phone": "+18108772530",
        "tags": [
          "gbp-call",
          "new-lead",
          "lsa-call"
        ],
        "type": "TYPE_PHONE",
        "scoring": [],
        "attributed": null,
        "email": null,
        "sort": [
          1751052416654
        ]
      },
      {
        "id": "D2F8GG9edSyf1en3uLC2",
        "locationId": "SXzmY6HCrn4NO3NdbMeh",
        "dateAdded": 1751049132495,
        "dateUpdated": 1751049132727,
        "lastMessageDate": 1751049132652,
        "lastMessageType": "TYPE_CALL",
        "lastMessageDirection": "inbound",
        "unreadCount": 1,
        "lastManualMessageDate": 1751049132652,
        "followers": [],
        "isLastMessageInternalComment": false,
        "contactId": "M9OT6F2tWku9DO2RrNtR",
        "fullName": null,
        "contactName": "(505) 628-9446",
        "companyName": null,
        "phone": "+15056289446",
        "tags": [
          "lsa-call"
        ],
        "type": "TYPE_PHONE",
        "scoring": [],
        "attributed": null,
        "email": null,
        "sort": [
          1751049132652
        ]
      },
      {
        "id": "9UYkV3XfKWZIzqMed16H",
        "locationId": "SXzmY6HCrn4NO3NdbMeh",
        "dateAdded": 1751033171670,
        "dateUpdated": 1751033171861,
        "lastMessageDate": 1751033171794,
        "lastMessageType": "TYPE_CALL",
        "lastMessageDirection": "inbound",
        "unreadCount": 1,
        "lastManualMessageDate": 1751033171794,
        "followers": [],
        "isLastMessageInternalComment": false,
        "contactId": "klCrRn6gO6GvIae3LhVt",
        "fullName": null,
        "contactName": "(810) 660-0597",
        "companyName": null,
        "phone": "+18106600597",
        "tags": [
          "lsa-call"
        ],
        "type": "TYPE_PHONE",
        "scoring": [],
        "attributed": null,
        "email": null,
        "sort": [
          1751033171794
        ]
      },
      {
        "id": "E1rAr5uXOguKCJEoOfjR",
        "locationId": "SXzmY6HCrn4NO3NdbMeh",
        "dateAdded": 1750970373409,
        "dateUpdated": 1750970373561,
        "lastMessageDate": 1750970373507,
        "lastMessageType": "TYPE_CALL",
        "lastMessageDirection": "inbound",
        "unreadCount": 1,
        "lastManualMessageDate": 1750970373507,
        "followers": [],
        "isLastMessageInternalComment": false,
        "contactId": "tTUWL9abzCeX845Owpip",
        "fullName": null,
        "contactName": "(888) 534-8441",
        "companyName": null,
        "phone": "+18885348441",
        "tags": [
          "gbp-call",
          "new-lead"
        ],
        "type": "TYPE_PHONE",
        "scoring": [],
        "attributed": null,
        "email": null,
        "sort": [
          1750970373507
        ]
      },
      {
        "id": "Aa0EYEceDAbULkdRUqf1",
        "locationId": "SXzmY6HCrn4NO3NdbMeh",
        "dateAdded": 1750959010076,
        "dateUpdated": 1750960218417,
        "lastMessageDate": 1750960218358,
        "lastMessageType": "TYPE_CALL",
        "lastMessageDirection": "inbound",
        "unreadCount": 2,
        "lastManualMessageDate": 1750960218358,
        "followers": [],
        "isLastMessageInternalComment": false,
        "contactId": "LnEseiYCz3Dzo75v1mIL",
        "fullName": null,
        "contactName": "(810) 292-2922",
        "companyName": null,
        "phone": "+18102922922",
        "tags": [
          "gbp-call",
          "new-lead"
        ],
        "type": "TYPE_PHONE",
        "scoring": [],
        "attributed": null,
        "email": null,
        "sort": [
          1750960218358
        ]
      },
      {
        "id": "8DTRNjd1B5NwwbPfsQgM",
        "locationId": "SXzmY6HCrn4NO3NdbMeh",
        "dateAdded": 1750957444245,
        "dateUpdated": 1750957444502,
        "lastMessageDate": 1750957444412,
        "lastMessageType": "TYPE_CALL",
        "lastMessageDirection": "inbound",
        "unreadCount": 1,
        "lastManualMessageDate": 1750957444412,
        "followers": [],
        "isLastMessageInternalComment": false,
        "contactId": "WRgZdsBU31BjpBk2P9wG",
        "fullName": null,
        "contactName": "(586) 354-8329",
        "companyName": null,
        "phone": "+15863548329",
        "tags": [
          "lsa-call"
        ],
        "type": "TYPE_PHONE",
        "scoring": [],
        "attributed": null,
        "email": null,
        "sort": [
          1750957444412
        ]
      }
    ],
    "total": 304,
    "traceId": "a75a7fe9-d419-4063-9e92-82d9ea7fe03a"
  }
]

Can probably done like this:

Get the conversations and messages first, and proceed with all items.
The second loop seems to be a bit broken.
Hard to figure out how to connect the nodes.
After merging all the data in the first loop, the Loop node outputs all the data through the Done output, making it available for further processing.

Another approach to make the workflow easier and more relyable is to use a subworkflow (can be the same workflow).
But the solution with untaggling the loops stays the same.