Processing of input parameters

Mapping parameters

Mapping all parameters

{
    ...
    "body": {
        "firstName": "{{parameters.firstName}}",
        "lastName": "{{parameters.lastName}}",
        "email": "{{parameters.email}}"
    },
    ...
}

Notice, that you have to map every single parameter correctly.

There is a risk of a typo or omission of a parameter.

Using an IML function or omitting a parameter

Sometimes, you don't want to map all parameters in the body for some reason:

  • 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 the url

  • 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')}}"
        
    },
    ...
}

Notice, that you have to map every single parameter correctly.

There is a risk of a typo or omission of a parameter.

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)}}"
    },
    ...
}

It isn't possible to send a null value to a service.

{
    "url": "/messages.json",
    "method": "POST",
    "body": {
        "status": "active",
        "content": "{{if(parameters.content, paramteres.content, undefined)}}"
    },
    ...
}

It isn't possible to send a null, empty string, and 0 (zero) value to a service.

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.

Date parameters

When a field is a type "date", it should be possible to use our keyword "now" as a value, which means, the field should accept ISO-8601 date format and if the service requires only the date (no time) or a different format like timestamp, this formatting should happen inside the module.

Users of the app should never be prompted to format the date inputs the way API requires! Such apps will not be approved by Make.

Communication:

{
    "url": "/api/users",
    "method": "POST",
    "body": {
        "name": "{{parameters.name}}",
        "birthday": "{{formatDate(parameters.birthday, 'YYYY-MM-DD')}}",
        "due_date": "{{formatDate(parameters.due_date, 'X')}}"
    },
    "response": {
        "output": "{{body}}"
    }
}

Parameter birthday is required to have format YYYY-MM-DD and parameter due_date is required to be a timestamp by the service, so the formatting happens inside the Communication part of the module.

Parameters:

[
    {
        "name": "name",
        "type": "text",
        "label": "Name"
    },
    {
        "name": "birthday",
        "type": "date",
        "label": "Birthday"
    },
    {
        "name": "due_date",
        "type": "date",
        "label": "Due Date"
    }
]

The parameters birthday and due_date are correctly date typed and don't need to be formatted by the user, he can freely work with now keyword.

Query String (QS)

The query string parameters should be defined using the qs object in order not to be embedded directly in the URL. Embedded parameters are those parameters that are after a question mark.

This will enforce the correct encoding of both static and dynamic parameters.

If you need to specify a query string parameter, you can do:

{
    "url": "http://yourservice.com/api/users/{{parameters.userId}}?includeAdvanced={{parameters.advanced}}"
}

But a better way is to use a special qs collection.

The headers, qs, and body collections represent request headers, query string parameters, and body payload. The key is the variable/header name and the value is the variable/header value. You don’t need to escape values inside those collections.

The above request can be rewritten as:

{
    "url": "http://yourservice.com/api/users/{{parameters.userId}}",
    "qs": {
        "includeAdvanced": "{{parameters.advanced}}"
    }
}

NOTE: qs and headers are single-level collections, meaning that you cannot specify nested objects in their parameters:

{
    "qs": {
        "someProp": {
            "anotherOne": {
                "and-one-more": "THIS WILL NOT WORK"
            }
        }
    }
}

The example above will not work. But if you want dot notation for some reason, you can use it directly in the parameter name:

{
    "qs": {
        "someProp.anotherOne.and-one-more": "THIS WILL WORK"
    }
}

This will create a query string that looks like this: ?someProp.anotherOne.and-one-more=THIS%20WILL%20WORK

Last updated