Coding an UbiFunction
Last updated
Was this helpful?
Last updated
Was this helpful?
UbiFunctions accept or , which means you can use these languages to write the required logic to extract, transform, and analyze data.
Regardless of the chosen runtime, the UbiFunction must define a main function. This function serves as the entrypoint, meaning it is the first function called when a request is made to the UbiFunction.
UbiFunctions require a JSON payload to be sent 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 the parameters sent in the request, making them accessible within your function for further usage.
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
.
Object
Description
args
Any payload sent to the function will be contained by the args
object.
args.token
When an x-auth-token
header is included in an HTTP invokation request, the args.token
key will be included.
By default, every new UbiFunction has a sample code that uses input data (token
, device
, and a variable value
) to make a request to Ubidots API. Here are the default examples for your reference:
The output of an UbiFunction must be a JSON object. By default, the status code will be 200
, but this could be changed using .