Hubspot find contacts empty results breaks workflow?

Hi,

I’m looking to use n8n to automate some work with Hubspot. I’m struggling at the moment with the find contacts nodes.

If I have an array of items as an output => I only get results for items that actually exists in Hubspot so it breaks all others nodes… Is it something intended? Am I missing something?

{
  "name": "Leads",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        60,
        310
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "getAll",
        "limit": "=10",
        "additionalFields": {
          "format": "resolved",
          "q": "=from:([email protected]) AND NOT label:n8nDone"
        }
      },
      "name": "retrieve Formation emails",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 1,
      "position": [
        360,
        310
      ],
      "credentials": {
        "gmailOAuth2": "gmail"
      }
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [],
          "number": [
            {
              "value1": "={{Object.keys($json).length}}",
              "operation": "larger"
            }
          ],
          "string": []
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1060,
        310
      ]
    },
    {
      "parameters": {
        "resource": "contact",
        "operation": "search",
        "limit": 1,
        "filterGroupsUi": {
          "filterGroupsValues": [
            {
              "filtersUi": {
                "filterValues": [
                  {
                    "propertyName": "email",
                    "value": "={{$json[\"email\"]}}"
                  }
                ]
              }
            }
          ]
        },
        "additionalFields": {}
      },
      "name": "Find contact",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 1,
      "position": [
        820,
        310
      ],
      "alwaysOutputData": false,
      "credentials": {
        "hubspotApi": "Hubspot"
      }
    },
    {
      "parameters": {
        "functionCode": "var data = [];\nitems.forEach(function(item){\n      var text = item.json.textAsHtml;\n      var place = (text.split('Votre &eacute;tablissement : ')[1]).split('<br/>')[0];\n      var zipCode = place.split(' ')[1];\n      var name = (text.split('Demandeur : ')[1]).split('<br/>')[0]; \n      var lastName = name.split(\" \")[0];\n      data.push({\n        json:{\n          emailId: item.json.id,\n          place:place,\n          zipCode: zipCode,\n          city: (place.split(zipCode)[1]),\n          name:name,\n          lastName:lastName,\n          firstName:name.split(lastName+\" \")[1],\n          trainingName:(text.split('souhait&eacute;e : ')[1]).split('<br/>')[0],\n          education: (text.split('Niveau de formation : ')[1]).split('<br/>')[0],\n          phone: (text.split('T&eacute;l : ')[1]).split('<br/>')[0],\n          message: (text.split('Message du candidat :')[1]).split('Adresse :')[0],\n          email: (text.split(\"mailto:\")[1]).split(\"\\\"\")[0]\n        }\n      });\n});\nreturn data;"
      },
      "name": "Parse data (formation)",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        580,
        310
      ]
    },
    {
      "parameters": {
        "resource": "contact",
        "email": "={{$node[\"Parse data (formation)\"].json[\"email\"]}}",
        "additionalFields": {
          "customPropertiesUi": {
            "customPropertiesValues": [
              {
                "property": "contact_wensei",
                "value": "true"
              }
            ]
          },
          "firstName": "={{$node[\"Parse data (formation)\"].json[\"firstName\"]}}",
          "lastName": "={{$node[\"Parse data (formation)\"].json[\"lastName\"]}}",
          "phoneNumber": "={{$node[\"Parse data (formation)\"].json[\"phone\"]}}"
        }
      },
      "name": "Hubspot",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 1,
      "position": [
        1070,
        640
      ],
      "credentials": {
        "hubspotApi": "Hubspot"
      }
    },
    {
      "parameters": {
        "stage": "=appointmentscheduled",
        "additionalFields": {
          "dealName": "={{$node[\"Parse data (formation)\"].json[\"name\"]}}",
          "amount": "0",
          "associatedVids": "={{$node[\"IF\"].json[\"id\"]}}"
        }
      },
      "name": "Hubspot1",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 1,
      "position": [
        1260,
        290
      ],
      "credentials": {
        "hubspotApi": "Hubspot"
      }
    },
    {
      "parameters": {
        "resource": "messageLabel",
        "messageId": "={{$node[\"Parse data (formation)\"].json[\"emailId\"]}}",
        "labelIds": [
          "Label_2575473674857323163"
        ]
      },
      "name": "Gmail",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 1,
      "position": [
        1490,
        290
      ],
      "credentials": {
        "gmailOAuth2": "gmail"
      }
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "retrieve Formation emails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "retrieve Formation emails": {
      "main": [
        [
          {
            "node": "Parse data (formation)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find contact": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Hubspot1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Hubspot",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse data (formation)": {
      "main": [
        [
          {
            "node": "Find contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Hubspot": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Hubspot1": {
      "main": [
        []
      ]
    }
  },
  "active": false,
  "settings": {},
  "id": "1"
}

Welcome to the community @vbarrier!

It does not break the workflow, it only stops the branch from executing. And yes, that is intended behavior. Each node executes for the incoming items, and if there are no items (because for example, the previous node does not return any) then it stops.

If you want to continue anyway, you can activate the option “Always Output Data” by setting it to true (can be found under “Settings” right from “Parameters”). It will emit an empty item if there are none, so that the workflow continues executing.

Hope that helps!

Thank you for your fast reply.

That’s what I did in the first place but I still don’t see how to catch the “empty” result in the next node “IF” I have :

{{Object.keys($json).length}}

But then in the next nodes it creates a “deal” in hubspot with the data of the first item

Any hints?

Yes, that looks correct. If you use that in an IF-Node which checks for “number” 0 it should work fine.

If you reference in that Hubspot-Node then another node (with an expression like $node...) which is before the other Hubspot-Node (the one that queries nonexisting contacts and so does not return any data), then it is exactly what would happen. After all, is the node you are refering outputting that data. If you want to use the incoming data, you have to use $json.

Then I don’t understand why it doesn’t work :frowning:

If I play the whole workflow it goes to the end (with only one item done) If I play from the IF-Node then it fails with:

"Cannot read property '0' of undefined"

And how can I access to the item data before the Hubspot-Node that check if the contact already exists in order to use that data in a Hubspot-Node that create the new contact.

I’m a bit lost… I can share my n8n server access, if it can help to reproduce.

BTW: If I check “Always Output Data” on a NODE, it should display results with empty data? It would help to keep the “right items count” in a more visual way. no?

I made a simple test that confirm that I loose the “empty” data needed as output from Hubspot-Node (search contact by email with always output data checked):

Input of the Node (one contact exists)

Only one row as output (instead of empty/data/empty)

Am I right?

Sorry, do not understand at all. You can share a simple version of your workflow (best with mock data) which shows your problem. We can then have a look.

What it does, is that it will return one item (and only one) if the node would normally return nothing at all. If you want to get all the data from a previous node again in the branch you can do that with a Merge-Node in mode “Pass-through”.

I have 3 items (with emails / first name / last name /) grabbed from emails then I need to check for each of them if they are in Hubspot using Hubspot Node and their email (contact->find) but the node will not give me a result per item.

For example :

-> output gmail, 3 items : [email protected] / [email protected] fr / [email protected]

-> output hubspot node : json_object_for test / json_object_for test3 (test2 doesn’t exist no data)

-> I use an IF to check if their is an object from Hubspot returned in order to use it OR I need to create a contact in hubspot

=> This is where it doesn’t work my test2 doesn’t exist anymore, and I can’t easily detect the “no data” from the hubspot node… I see two solutions : Hubspot return always something (empty array if not found) or the “always output data” should work per item.

I hope it is more clear…

Quick questions. Why do you want to check if the email exist? if it does not exist do you want to save it on Hubspot? If that is the case, can’t you just use the create/update operation?

Thank you for your reply :slight_smile:

Why do you want to check if the email exist?

Yes

if it does not exist do you want to save it on Hubspot?

Yes with data from the email grabbed

If that is the case, can’t you just use the create/update operation?

Because it will update an existing contact with maybe some values I don’t want to update beside the fact that it could be a useless PUT request.

@vbarrier I will do something like this.

{
  "nodes": [
    {
      "parameters": {
        "resource": "contact",
        "operation": "search",
        "additionalFields": {
          "query": "={{$node[\"SplitInBatches\"].json[\"email\"]}}"
        }
      },
      "name": "Hubspot",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 1,
      "position": [
        1070,
        300
      ],
      "alwaysOutputData": true,
      "credentials": {
        "hubspotApi": "asasas"
      }
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "name": "SplitInBatches",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        780,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{$node[\"SplitInBatches\"].context[\"noItemsLeft\"]}}",
              "value2": true
            }
          ]
        }
      },
      "name": "IF1",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1260,
        630
      ]
    }
  ],
  "connections": {
    "Hubspot": {
      "main": [
        [
          {
            "node": "IF1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SplitInBatches": {
      "main": [
        [
          {
            "node": "Hubspot",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF1": {
      "main": [
        null,
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Thank you :slight_smile:

I’m learning how your tool works! :wink:

@vbarrier Of course. Let me know if that helped.