Skip to main content

I have a three step zap for updating a client in our CRM, triggered if they open an email from a 3rd party application. I’ve successfully created the trigger (1) that finds the subscriber from the CRM (2) and returns an object, structured as following (omitting non-necessary data):

{
"data": {
"type": "prospect",
"id": 1436,
"attributes": {
"tags": :
"California","C-Level","AZ","CIO","PST"
]
}
}
}

The 3rd step asks the user for a New Tag to add to “tags”, whereby I need to append the New Tag to the existing list of tags.

I am successful in posting (patch in my case) to the API, but my data is malformed and ends up being one long string as a tag (literally, the tag at the CRM is “California, C-Level, AZ, CIO, PST, TestTag” instead of individual tags). Following is my current code…

const newTags = bundle.inputData.tags + ',' + bundle.inputData.new_tag;
const options = {
url: `https://api.outreach.io/api/v2/prospects/${bundle.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]
}
}
}
}

Please help me with how I can append .new_tag to the existing .tags list and how it should look in the body.

Much appreciated!

Two quick things to try: 

  1. Convert the string to an array before sending to your API:

"attributes": { "tags": newTags.split(',') }

 

  1. Treat tags as a “line item” in the input field for your action.

That was it. My code ended up looking like the following. 

 

const newTags = bundle.inputData.tags + ',' + bundle.inputData.new_tag;
const options = {
url: `https://api.outreach.io/api/v2/prospects/${bundle.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;
});

Thanks for the help!

Scott