Modify the request body based on parameter type, before it has been sent to the API

Hello,
I’m creating a custom app with an action module, and in the communication tab in the module, I pass the parameters in body as the following:

"body": {
		"{{...}}": "{{omit(parameters, 'appId')}}"
	  } 

The parameters are dynamically generated from a defined remote procedure, and vary depending on user selection, which means I don’t know the names of the parameters, and also I don’t know how many, and what is the type of each parameter (text, boolean, … etc). Here is the remote procedure definition:

{
	"url": "/services/app/Fields/GetAll",
	"method": "GET",
	"qs": {"listId": "{{parameters.listId}}"},
	"body": {},
	"headers": {},
	"response": {
		"iterate": "{{body.result.items}}",
		"output": {
			"label": "{{item.name}}",
			"value": "{{item.id}}",
			"type": "{{switch(item.dataType;0;'text';1;'number';2;'date';3;'boolean';7;'url';8;'email';9;'file';13;'number';'any')}}"
		}
	}
}

Now, when I run the scenario, the module sends the request body to my API as the following:

{
    "1052046": "Test make integration 22",
    "1052051": true,
    "1052052": "blue",
    "1052067": "zambia",
}

I need to detect the type of the parameter, here in my example is “1052067”: “zambia”, and then change the request payload to be as the following:

{
    "1052046": "Test make integration 22",
    "1052051": true,
    "1052052": "blue",
    "1052067": [
        {
            "_id": null,
            "label": "zambia"
        }
    ],
}

Would you please help, any suggestion to achieve this?
Thank you.

Hello Hisham,

To achieve this, you will need to implement a custom IML function.

An example of a custom IML function together with an explanation of implementation can be found here.

Since currently the custom IML functions are temporarily disabled in all accounts, you will need to contact Support for assistance. Support will help you with the creation or update of a custom IML function.

2 Likes