I have a Zapier that is using input fields and and a dynamic field that is pulling and gathering custom field data from an email marketing platform.
Normally when I pass the information, I use the Key from the Input Fields.The Dynamic Field does not have one.
I am also adding my code to pass the input fields that I have so far. I am also going to need to pass more than one item for the dynamic content, not sure if that would be an if statement and how to do that.
Dynamic Field Code:
// Configure a request to an endpoint of your api that
// returns custom field meta data for the authenticated
// user. Don't forget to congigure authentication!
const options = {
url: 'https://edapi.example.com/v1/Database',
method: 'GET',
headers: {
'X-API-KEY': bundle.authData.ApiKey
},
params: {
'ApiKey': bundle.authData.ApiKey
}
};
return z.request(options).then((response) => {
response.throwForStatus();
const results = response.json;
var col = results.DatabaseColumns.filter((item) => item.IsCustom).map((item) => {
return {
...item,
key: item["ColumnName"],
value: item["ColumnName"]
};
});
//var col = col.filter(items => ['FirstName', 'LastName'].indexOf(items) >= 0 )
for (var i = col.length; i--;) {
if (col[i].key === 'FirstName' || col[i].key === 'LastName' ) {
col.splice(i, 1);
}
}
return col});
/*
return [
{
"key": "FirstName",
"value":"First Name"
},
{
"key": "LastName",
"value": "Last Name"
},
{
"key": "Test",
"value": "Test 2"
},
*/
Post API code so far:
const options = {
url: 'https://edapi.example.com/v1/Subscribers',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-API-KEY': bundle.authData.ApiKey
},
params: {
'ApiKey': bundle.authData.ApiKey
},
body: {
'EmailAddress': bundle.inputData.EmailAddress,
'CustomFields':[
{
'FieldName':'FirstName',
'Value':bundle.inputData.FirstName,
},
{
'FieldName':'LastName',
'Value':bundle.inputData.LastName,
},
{
'FieldName':'FirstName',
'Value':bundle.inputData.FirstName,
},
],
'Lists':[
bundle.inputData.ListID,
]}};