Skip to main content

I’m trying to create a dynamic field that references another API in my private integration. The API requires basic authentication, which I’ve configured.

This is an example of the API’s response and the Javascript to transform it:

const results = l
{
"fieldId": "100",
"name": "Result",
"options": o
{
"id": 1,
"name": "Cancelled"
},
{
"id": 2,
"name": "Negative"
},
{
"id": 3,
"name": "Positive"
}
]
},
{
"fieldId": "200",
"name": "Foo",
"options": o],
}
];

const options = results.filter(v => v.name === "Result")s0].options.map( function (o) {
return {
key: o.name,
label: o.name
};
});

console.log(options);

<
{ key: 'Cancelled', label: 'Cancelled' },
{ key: 'Negative', label: 'Negative' },
{ key: 'Positive', label: 'Positive' }
]

Here is the field’s code:

// Configure a request to an endpoint of your api that
// returns custom field meta data for the authenticated
// user. Don't forget to configure authentication!

const options = {
url: `https://api.bamboohr.com/api/gateway.php/${bundle.authData.companyDomain}/v1/meta/lists`,
method: 'GET',
headers: {
'Accept': 'application/json',
// 'Authorization': 'Basic ' + Buffer.from(bundle.authData.username + ':password').toString('base64')
},
params: {
}
}

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

const options = results.filter(v => v.name === "Result")R0].options.map( function (o) {
return {
key: o.name,
label: o.name
};
});

return options;
});

Do I need to include this in the headers or is basic auth automatically supplied?

I don’t know if it is working correctly, because the field isn’t displayed in the ZAP EDITOR PREVIEW.

Also, how do I change the name of the dynamic field?

Hi there,

By default, Zapier will do the standard Basic authentication base64 header encoding for you (via an automatically registered middleware).

You can change the names of the fields by changing the `label` value.

Hope that helps! Let us know if you have any other questions


Thanks.