Skip to main content
All CollectionsDeveloper Guides
UbiFunctions: Process/Parse data from 3rd party platforms
UbiFunctions: Process/Parse data from 3rd party platforms

Use UbiFunctions to create your own API and gain access to data, APIs, and tools using HTTPS.

Sergio M avatar
Written by Sergio M
Updated over 3 months ago

One of the most exciting things about IoT is its broad solution architecture capabilities – giving engineers, developers, and innovators complete control from device management in the field to advanced project-specific data cleansing and anomaly detection for preventative analytics in factories. For example, you could choose to send data directly to Ubidots from an HTTP/MQTT capable device, or you can use a device-management cloud from the hardware supplier to receive data and then relay this data via a webhook to Ubidots for data visualization, calculation, and storage. If you then wish to overlay another 3rd party data analytics API, to enhance your data beyond Ubidots framework - simply export the data equally as easily with UbiFunctions. System Integrators have a new best friend in UbiFunctions as they can now connect a solution's IoT layers into a single display and platform. 

In the diagram below we see a typical IoT Solution. Here we can see the "Device Management" layer which can be used for OTA Updates, device reboots, and other essential hardware related features.

Here some typical cases where a 3rd party layer is used between devices and Ubidots:

While most of the above platforms are flexible enough to setup HTTPS webhooks or callbacks in the JSON format expected by Ubidots API, there might be instances where additional processing is required, and we designed the UbiFunctions engine just for these instances.

What is a Parser?

A parser is a Node.js or Python3 cloud function that executes when an GET or POST HTTPS request is made to the Parser's URL:

Create a Function

This feature can be accessed from the "Devices" tab of your Ubidots header by selecting "Functions" 

Step 1: Click the blue "+" icon to create your first parsing function:

Step 2: Give it a name that describes the type of device you're using. I recommend using the format "Brand-Reference", i.e. "mcthings-mctrack" or "digitalmatter-oyster".

Step 3: Click on "Make it live" to deploy an API endpoint URL containing the name of your function. You should see the updated URL:

Code your function to Parse

UbiFunctions accepts NodeJS LTS, which means you can use Javascript functions to parse your data. The code snippet receives "args" as a dictionary and performs the desired data transformation. The code is run whenever the endpoint URL is requested.

By default, a simple code is included which will return the same data received:

function main(args) {

    return args;

}

We could also return an arbitrary dictionary:

function main(args) {

    return {"Hello":"World"};

}


Please note the return payload must always be a dictionary.

Run your Function

Click on "Run Function" to test your code. A modal screen will appear requesting the input data. You may leave this blank if desired. 

After clicking on "Run with this input" a console window will emerge with both the output and the console of the results:

  • Output: This is what your parsing function returns. It must be a dictionary. Use "return" to quit the function and return the dictionary.

  • Console: This is used for debugging purposes. Use console.log("hello") to leave trails in this console.

Need help coding your parser? Feel free to ask for help to our support team via the in-app chat channel or via email at support@ubidots.com

Want to share a helpful parser to teach others how to connect the dots? Feel free to post it at community.ubidots.com and help another IoT innovator achieve their goals. 

Did this answer your question?