For the complete documentation index, see llms.txt. This page is also available as Markdown.

Coding an UbiFunction

Runtimes

UbiFunctions accept NodeJS or Python. You can use these languages to write the logic required to extract, transform, and analyze data.

Entrypoint

Regardless of the chosen runtime, the UbiFunction must define a main function. This function serves as the entry point, meaning it is the first function called when a request is made to the UbiFunction.

UbiFunction arguments

UbiFunctions require a JSON payload in the body of the HTTP request. This payload is passed to the main function as a dictionary object named args. The args object contains all parameters sent in the request, making them accessible within your function for further use.

For UbiFunctions configured with the GET method, the args object instead contains the query parameters passed in the URL.

Additionally, when an X-Auth-Token header is included in the request, its value is automatically injected into args as args["token"], regardless of whether the request is made via GET or POST.

async function main(args) {
  var ubidots_token = args?.token;
  var device_label = args.device;
}
def main(args):
    token = args.get('token', None)
    device = args.get('device', None)
Object
Description

args

Any payload sent to the function will be contained in the args object.

args.token

When an x-auth-token header is included in an HTTP invocation request, the args.token key will be included.

Behavior of the args object according to HTTP methods

Code

By default, every new UbiFunction includes sample code that uses input data (token, device, and a variable value) to make a request to the Ubidots API. Here are the default examples for reference:

Output Response

The output of a UbiFunction must be a JSON object. By default, the status code will be 200, but this can be changed using Raw Functions.

Last updated

Was this helpful?