Type "json"

Sometimes your function needs more complex data as input: let's say that you need a JSON service account to authenticate against a third-party API. You can use environment variables of type json in your implementation, and then our platform will ask consumers to enter their value during installation.

The type json variables allow the consumers of a function to enter any json object valid, which you need to define using the schema prop. This type is presented in the installation UI form as a JSON input (see image below), but ultimately you can only access them as strings in your function implementation.

Example of an environment variable type "json" definition

"env": [
    {
        "name": "DATA_PROJECTION",
        "description": "The projection in JSON format that will be used to filter the fields that you want to synchronize.",
        "required": true,
        "type": "json",
        "schema": {
            "type": "object",
            "minProperties": 1,
            "patternProperties" : {
                "^.*$" : {
                    "anyOf": [
                        {
                            "type": "integer",
                            "enum": [0, 1]

                        },
                        {
                            "type": "boolean"
                        },
                        {
                            "$ref": "#"
                        }
                    ]
                }
            }     
        }
    }
]

Example of how to consume the value of the environment variable within the function implementation

const myFunction = () => {
    const dataProjection = JSON.parse(process.env.DATA_PROJECTION)
    ...
};

module.exports = myFunction;

Properties of the type

Last updated