Make Apps
Search
K

Dynamic mappable parameters

When the API service supports fields with different names of formats from Make, you need to implement a custom IML function that will assist as a conversion table. This conversion table has a list of API formats and their equivalents in Make. E. g., when the API returns a field of type single_line_text, in Make it will be evaluated as text. Also, you can use the additional parameters available, e. g. whether the parameter is mandatory or optional, what are available options in selects, etc.
An example of fields in API:
{
"data": {
"fields": [
{
"id": "1",
"name": "Birthday",
"type": "anniversary",
"position": 0,
"mandatory": false,
"reminder_days": 0
},
{
"id": "2",
"name": "CF Single Line Text",
"type": "single_line_text",
"position": 1,
"mandatory": false
},
{
"id": "3",
"name": "CF Multi Line Text",
"type": "multi_line_text",
"position": 2,
"mandatory": false
},
{
"id": "4",
"name": "CF Number",
"type": "number",
"position": 3,
"mandatory": false
},
{
"id": "5",
"name": "CF Dropdown",
"type": "select_box",
"position": 4,
"mandatory": false,
"choices": [
"a",
"b",
"c"
]
},
{
"id": "6",
"name": "CF Date",
"type": "date",
"position": 5,
"mandatory": false
},
{
"id": "7",
"name": "CF Checkbox",
"type": "multiple_choice",
"position": 6,
"mandatory": false,
"choices": [
"1",
"2",
"3"
]
}
]
}
}
Example of communication:
{
"url": "/contacts",
"method": "POST",
"body": "{{parameters}}",
"response": {
"output": "{{body}}"
}
}
An example of mappable parameters:
[
"rpc://getFields"
]
An example of RPC:
{
"url": "/fields",
"method": "GET",
"qs": {
"per_page": 100
},
"response": {
"output": "{{dynamicFields(body.data.fields)}}"
}
}
An example of IML function:
function dynamicFields(fields) {
let arr = [];
if(!fields) return;
fields.forEach(item => {
let obj = {};
let key = item.custom_field;
obj.name = key.id;
obj.label = key.name;
obj.required = key.mandatory;
switch (key.type) {
case "anniversary":
case "date":
obj.type = 'date';
break;
case "multi_line_text": //multi line text
obj.multiline = true;
case "single_line_text": //single line text
obj.type = 'text';
break;
case "number":
obj.type = 'number';
break;
case "multiple_choice": //multiple choice
obj.multiple = true;
case "select_box": //single choice
obj.type = 'select';
obj.options = key.choices.map(option => {
let obj = {};
obj.label = option;
obj.value = option;
return obj;
});
break;
default:
return;
}
arr.push(obj);
});
return {
name: "data",
label: "Data",
type: "collection",
spec: arr
};
}
Example request:
Occurence in a module
Request
Example of dynamic mappable parameters
{
"2": "Example of single line text.",
"4": 123,
"5": "a",
"6": "2022-09-20T17:42:31.792Z",
"7": [
"1",
"2"
]
}