Processing of input parameters
Mapping all parameters
{
...
"body": {
"firstName": "{{parameters.firstName}}",
"lastName": "{{parameters.lastName}}",
"email": "{{parameters.email}}"
},
// ... other directives
}
Using an IML function or omitting a parameter
Sometimes, you don't want to map all parameters in the body
. Some reasons may include:
the parameter shouldn't be sent at all (technical parameters such as selects, etc.).
the parameter should be sent somewhere else than in the
body
, e.g. in theurl
.the parameter has to be wrapped in an IML or custom IML function.
{
"url": "/contact/{{parameters.id}}",
"method": "PUT",
"body": {
"email": "{{parameters.email}}",
"firstName": "{{parameters.firstName}}",
"lastName": "{{parameters.lastName}}",
"registrationDate": "{{formatDate(parameters.registrationDate, 'YYYY-MM-DD')}}"
},
// ...
}
Handling arrays, nulls, and empty strings
Make and other third-party services transport values in many different formats. It is important to know how to handle the value types of arrays, nulls, and empty strings.
Bad practices
{
"url": "/messages.json",
"method": "POST",
"body": {
"status": "active",
"content": "{{ifempty(parameters.content, undefined)}}"
},
// ...
}
{
"url": "/messages.json",
"method": "POST",
"body": {
"status": "active",
"content": "{{if(parameters.content, parameters.content, undefined)}}"
},
// ...
}
Let users decide what parameters they want to send to the service. Make has a feature to show how to process values. This feature allows users to define exactly how Make should behave when the value is "empty".
For example, if a user defines that they want to send a specific field to a service even if the value is null
, empty string, or an empty array, it will be sent to the service. In module communication, config passes parameters without any modification.
Query String (QS)
Query string parameters should be defined using the qs
directive as a key-value collection, where the key is the parameter name and the value is the parameter value. Values in the qs
collection are automatically encoded, so you do not need to escape them manually.
{
"url": "http://yourservice.com/api/items",
"qs": {
"limit": 100,
"since": "{{parameters.since}}",
"until": "{{parameters.until}}"
}
// ... other directives
}
This will issue the request to URL in this way:
http://yourservice.com/api/items?limit=100&since=2023-01-01&until=2023-01-31
If you provide a query string directly in the url
directive, it won't be automatically encoded. You have to encode it manually. But in common cases, the entering query string in url
is not a recommended approach, especially when values are inserted dynamically. See the Special case: Query string parameters in the URL section for more details.
Special case: Query string parameters in the URL
In most cases, having the query string in the URL is not the best practice. It is better to use the qs
collection, but sometimes there may be a special case when you need to use the query string directly in the URL.
The main difference is that the query string in the URL is not encoded automatically, so you have to do it manually. This can be useful when the third-party service requires a very specific format or encoding of the query string parameters. In that case, you can add a query string directly to the url
directive string and manage the encoding yourself.
Example of specific query string parameters in the URL:
{
"url": "http://yourservice.com/api/users/{{parameters.userId}}?groups=(1,2,3,4)&specificallyEncodedParameter={{parameters.specific}}",
// qs: {} // <- Do not include the `qs` collection here
"method": "POST",
// ...
}
The most common use case for this is when a third-party service requires special symbols like brackets []
or parentheses ()
to be unencoded in the query string.
Using arrays in qs
qs
You can also use an array as a value in the qs
collection. In this case, the resulting query string will repeat the key for each value in the array, e.g. ?tag=one&tag=two&tag=three
.
{
"url": "http://yourservice.com/api/items",
"qs": {
"anytag": ["one", "two", "three"]
}
}
This will issue the request to URL in this way:
http://yourservice.com/api/items?anytag=one&anytag=two&anytag=three
Using structured data in qs
qs
{
"qs": {
"person": {
"address": {
"street": "123 Main Street"
}
}
}
}
Last updated