Function Inputs

Overview of function inputs

In different scenarios, your functions might receive different inputs from CodeMash. Here are all the available scenarios when a certain input is passed to your function.

General form

In general, all of your functions will receive two parameters - event and context parameter. The event parameter is some kind of data depending on how a function was called. The context parameter is just some information about the function itself. Your function handler (entry function) might look like the following.

function handler(event, context) { ... }

Where event is of the following form:

{
    projectId: "{YOUR_PROJECT_ID}",
    input: { ... }
}

Function event input

As stated above, the event input parameter varies depending on how the function was invoked. The following shows all the different input forms.

Calling through API

When calling a function through an API call your event will have the following form.

{
    projectId: "{YOUR_PROJECT_ID}",
    input: {
        "initiatorUserId": "{CALLER_USER_ID}",
        "template": "{ ... }",
        "data": "My custom data, can be any string"
    }
}

Collection triggers

When the function is invoked from the collection trigger your event will have the following form.

{
    projectId: "{YOUR_PROJECT_ID}",
    input: {
        "initiatorUserId": "{TRIGGER_USER_ID}",
        "template": "{ .. }",
        "collectionName": "my-collection",
        "triggerType": "Insert",
        "formerRecord": "{ ... }",
        "newRecord": "{ ... }"
    }
}

User triggers

‌When the function is invoked from the user trigger your event input will have the following form.

{
    projectId: "{YOUR_PROJECT_ID}",
    input: {
        "initiatorUserId": "{TRIGGER_USER_ID}",
        "template": "{ .. }",
        "collectionName": "my-collection",
        "triggerType": "Register",
        "formerUser": "{ ... }",
        "newUser": "{ ... }"
    }
}

The form of former and new users is as follows.

File triggers

‌When the function is invoked from the file trigger your event input will have the following form.

{
    projectId: "{YOUR_PROJECT_ID}",
    input: {
        "initiatorUserId": "{TRIGGER_USER_ID}",
        "template": "{ .. }",
        "collectionName": "my-collection",
        "triggerType": "Register",
        "formerFile": "{ ... }",
        "newFile": "{ ... }"
    }
}

The form of a former and new file are as follows.

Last updated