Best answer

Potential Bug in Phantombuster to Zapier "Run Javascript" workflow

  • 4 September 2020
  • 5 replies
  • 168 views

Userlevel 1

 This post is a follow up to the post made a few weeks ago: Phantombuster to Snov.io Zap question

What I am trying to do is that when a prospect that is scraped using Phantombuster does not have an email that is found, I want to remove that prospect entirely from the data set. That way, the emails that are scraped match the prospects they belong to and can be imported into Snovio.

The data I am getting from the Phantombuster scrape looks ok. Here is how I am mapping the keys from the Phantombuster output to the Run Javascript step:

When I apply the following JavaScript code, it ends up muddling the information.

// get Input Data field names
let keys = Object.keys(inputData)
let data = [];
console.log(inputData);
// loop through each Input Data field
for (let key of keys) {
// split the contents of each Input Data field on the commas into an array
let li = inputData[key].split(",");
for (let i=0; i<li.length; i++) {
if (typeof data[i] === "undefined") data[i] = {};
data[i][key] = li[i];
// add a record number (in case we want to break the fork/loop with a Filter)
data[i].recordNumber = i+1;
}
}

for (var i=0; i < data.length; i++) {

if (data[i]["Email"] == '' || !data[i]["Email"]) data[i] = null;
}
data = data.filter(function (el) {
return el != null;
});
// preview the whole data structure in the output
console.log(data);
// output the data
output = data;

When Phantombuster cannot find an email for a particular prospect, it assigns that key a blank string. So when the Phantom runs it scrapes 10 prospects and usually there are only 4 or 5 emails that are found. 

Here is the corresponding console log for an example run:

Not really sure what is happening here, can anyone from @Zapier advise? 

icon

Best answer by PaulKortman 12 November 2020, 00:06

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

5 replies

Userlevel 7
Badge +11

Hi @trevorSkyCiv!

Let me see if one of our more code-experienced mods can help you out with this one. @ikbelkirasan @PaulKortman any ideas here? Thanks!

Userlevel 1

@nicksimard Hoping to bump this up since we haven’t heard anything from the code-experienced mods. I would imagine people that are integrating with similar flows are having a similar issue. 

Userlevel 7
Badge +10

@trevorSkyCiv this is a common occurrence with Zapier and how it treats arrays with empty leading values. 

 

What I’ve tried in the past is to throw in dummy data in the front so it doesn’t think the array is starting with an empty value…  so for your inputData for Email I might do something like this:

email@exmaple.com,{{Array of Email values from previous step}}

and do that for each array and then in the output you can drop the first value data[0] if needed. 
 

Userlevel 1

@PaulKortman Thanks for the message, we tried a variety of different things like this to get it to how we want it, but it still seems like there is a bug in the backend of Zapier and the Phantombuster Zap step. Overall from how we understand it, the issue is with the Input Data mapping part. If there are empty entries, inputData comes out misaligned:

 

After this runs, instead of passing empty strings under the “Email” key, they are deleting that index altogether. This creates the mismatch in inputData between email and first name, as shown below:

Not sure if that changes anything or if this is the same as the original question, but we are really hoping to figure this out since it would make a huge difference in our operations. 

Userlevel 7
Badge +10

@trevorSkyCiv this is still the same problem… you have empty values in the begining of your array

 

You need to put something in front of that and maybe it will work, so if the value of email is currently set to

{{Result Object Mail From Drop Contact}}

You need to change it to be:

fake@email.com,{{Result Object Mail From Drop Contact}}

And then add a leading fake value for each of your variables… is First Name, Last Name, Company name, etc. That will help line things up. 

The key is that Zapier does not handle arrays with an empty value as the first item… it collaposes the first empty values so in your example the 4th email address will show up as the first, because 1, 2, and 3 are empty so Zapier collapses those and just skips right to the 4th value in the array.

 

When Zapier does this it does a similar behavior to the second array (First name) but since the first value in that array has a non-empty value then it doesn’t skip it, so your 4th value in your email address is now the first and the first value in your first name is also first, so thus things do not line up.

 

If you;d rather pay for a consulting fee so we can do this live over zoom let me know (send me a direct message) and I’ll respond with a link to book a call with me so we can work through what might be tricky/difficult to understand here.