Question

Create a dynamic field

  • 13 January 2023
  • 2 replies
  • 212 views

Badge +1

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 = [
{
"fieldId": "100",
"name": "Result",
"options": [
{
"id": 1,
"name": "Cancelled"
},
{
"id": 2,
"name": "Negative"
},
{
"id": 3,
"name": "Positive"
}
]
},
{
"fieldId": "200",
"name": "Foo",
"options": [],
}
];

const options = results.filter(v => v.name === "Result")[0].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")[0].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?


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

2 replies

Userlevel 6
Badge +8

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

Badge +1

Thanks.