Skip to main content

I have a Zap app that starts by leveraging a Mailchimp open trigger. Once a user opens an email in Mailchimp, I want to add a tag to the prospect’s record in my CRM app. The way I am going about this after the Mailchimp trigger is two action steps (would love only one but don’t know how to do it otherwise):

  1. Find a Prospect via Email
  2. Add a Tag to Prospect

I have been successful in retrieving the prospect’s data with Find a Prospect via Email. It finds the prospect from the Mailchimp email address and returns that data, as follows (subset of full dataset):

{
"data":
{
"type": "prospect",
"id": 1436,
"attributes": {
"addedAt": null,
"addressCity": null,
"addressCountry": null,
"addressState": null,
"addressStreet": null,
"addressStreet2": null,
"addressZip": null,
"angelListUrl": null,
"availableAt": null,
"callOptedOut": false,
"callsOptStatus": null,
"callsOptedAt": null,
"campaignName": null,
"clickCount": 0,
"company": null,
"companyFollowers": null,
"companyFoundedAt": null,
"companyIndustry": null,
"companyLinkedIn": null,
"companyLinkedInEmployees": null,
"companyLocality": null,
"companyNatural": null,
"companySize": null,
"companyType": null,
"emails": "
"scott@.com"
],
"tags":
"California",
"C-Level",
"AZ",
"CIO",
"PST"
],
"timeZone": null,
"timeZoneIana": null,
"timeZoneInferred": null,
"title": null,
"touchedAt": "2021-05-27T18:21:50.000Z",
"trashedAt": null,
"twitterUrl": null,
"twitterUsername": null,
"updatedAt": "2021-06-01T20:15:01.000Z",
"voipPhones": p],
"websiteUrl1": null,
"websiteUrl2": null,
"websiteUrl3": null,
"workPhones": k]
}
}
]
}

My biggest challenge right now is in getting the existing tags from the “Find a Prospect via Email” step to “Add a Tag to Prospect” because I cannot seem to extract the tags data and prepare it for a PATCH call.

Following is code I found from a similar question on here in my API call for Find a Prospect via Email” whereby I am trying to extract the tags data and prepare it for the next step:

return z.request(options)
.then((response) => {
response.throwForStatus();
const results = response.json;

let existTags = /];
for (const item of results.tags) {
existTags.push(item.tag)
}

// You can do any parsing you need for results here before returning them

return bresults];
});

But I continue to get an error similar to the following:

results.tags is not iterable
What happened (You are seeing this because you are an admin):
  Starting GET request to https://api.outreach.io/api/v2/prospects
  Received 200 code from https://api.outreach.io/api/v2/prospects?filter%5Bemails%5D=scott%40smeester.com after 182ms
  Received content "{"data":e{"type":"prospect","id":1436,"attributes":{"addedAt":null,"addressCity":null,"addressCountr"
  results.tags is not iterable

 

Can you help me write the correct code in “Find a Prospect via Email” so that I can compile that array or object that I will use in the next step, “Add a Tag to Prospect” to add the new tag to? 

Thank you in advance!!

Scott

Following is my API call for “Add a Tag to Prospect” that is currently not working right now either, but you can see where I am going (I have been successful in making the PATCH call, just not fully successful with the tags). If I could just get “newTags” formatted properly before the PATCH call.

let newTags;

// newTags = bundle.find_prospect_via_email.outputData.tags + ',' + bundle.inputData.new_tag;


const options = {
url: `https://api.xxxxxx.io/api/v2/prospects/${bundle.find_prospect_via_email.inputData.id}`,
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${bundle.authData.access_token}`
},
params: {

},
body:{
"data": {
"type": "prospect",
"id": bundle.inputData.id,
"attributes": {
"tags": newTags.split(',')
}
}
}
}

return z.request(options)
.then((response) => {
response.throwForStatus();
const results = response.json;

// You can do any parsing you need for results here before returning them

return results;
});

 


Tagging @Troy Tessalone because you helped me find the right resource in the past!!


Hi @scottsmeester303 

Note: Not sure if this is right, but worth a try.

The returned Tags is an array, so you’d need to use the push method a new Tag into the Tags array, rather than try to treat it as a string and add with a comma delimiter.

https://www.w3schools.com/jsref/jsref_push.asp

 

 


Thanks, @Troy Tessalone - that totally makes sense. The thing that I’m struggling with now is how to get access to the “tags” array from the previous action step, find_prospect_via_email. Here’s what I have right now:

let newTags;

newTags = bundle.find_prospect_via_email.tags.push(bundle.inputData.new_tag);

With the following error.

“Cannot read property 'tags' of undefined What happened (You are seeing this because you are an admin): Executing creates.create_tag.operation.perform with bundle Cannot read property 'tags' of undefined”

All I need is “newTags” to be the correct array and your help would be apprecaited!


@ikbelkirasan Can you advise?


@scottsmeester303 In order to get the existing tags array from the Find a Prospect via Email step, you’ll need to add an input field named tags to your “Add a Tag to Prospect” action, this field should have the Allows Multiples checkbox checked (See the screenshot below), then in your zap, map this field to the output tags from the Find a Prospect via Email step.

Now when the action is run, you’ll receive the tags as an array of strings and you’ll be able to push new tags as needed.

Note: The input data is accessible via bundle.inputDatafor example: bundle.inputData.tags instead of bundle.find_prospect_via_email.tags.

 

 


@scottsmeester303 

Were you able to figure it out with the feedback from @ikbelkirasan above?


Hey @Troy Tessalone  - haven’t been able to get back to this. Probably today. Thanks for the help so far!


@Troy Tessalone @ikbelkirasan  I ended up hiring somebody on Upwork. The guy I hired did not use Allows Multiples. Instead he created a text input allows the user to select the tags from the CRM.

Here is the code for compiling the array for the PATCH api call:

let newTags;
let existingTags;
newTags = bundle.inputData.new_tag;
existingTags = bundle.inputData.existing_tag;
newTags = ((existingTags)?existingTags+','+bundle.inputData.new_tag:bundle.inputData.new_tag);
newTags = newTags.split(",");

Thanks for the help!