All Collections
User Guides
Automatically provision Devices and Variables with Ubidots API Labels
Automatically provision Devices and Variables with Ubidots API Labels

Skip the headache of device and variable setup in your Ubidots account by using Device and Variable API Labels in your firmware.

Sergio M avatar
Written by Sergio M
Updated over a week ago

One of the biggest headaches in IoT solution deployment is setting up and developing the cloud service to store and view multiple device's data. You must create different devices, variables, guarantee communication paths, and provision how to handle the data once it is sent to the cloud. With recent advancements in Ubidots API, we take the headache away by allowing API Labels to be used in your device's firmware to automatically populate your Ubidots account with a Device and its Variables upon receiving the first POST request. This means with one code you can now deploy hundreds of devices efficiently without having to manually setup every device with its variables in Ubidots.

If you are a common user of Ubidots, you will know that Ubidots used to work in the same manner as many other IoT platforms, using unique identifiers as IDs to recognize the device and variable created in your Ubidots account. Now you no longer have create each device and every variable thanks creation of API Labels.

What is a device/variable API Label? API Labels are unique identifiers for devices and variables to keep your data organized in the time-series backend of Ubidots. Each label is a specific identifier interpreted by Ubidots as single and unique way to differentiate between devices and variables for users. This is what allows you to transfer data between the device and Ubidots and visualize data without confusion or contamination of another devices' data. It is not recommended to change the Device Label or Variable Label as any adjustments to these inputs will result in errors and faulty data transmission.

Where can I find my API Label? Ubidots API Labels are a user self-created alpha and/or numeric unique identifier for the device and its variables. We recommend using the MAC Address of each device to guarantee a unique label to know which device matches its specific data display in Ubidots. Of course, the nomenclature is up to you so design as you see fit.

When using API Labels in your POST request, the devices and the variables are created automatically when the request is received by Ubidots. Below is a sample POST request for 3 sensors, but you can extend it to more if you desire.

POST Request Structure

POST /api/v1.6/devices/{API_LABEL_FOR DEVICE}/?token={TOKEN} HTTP/1.1
Content-Type: application/json
Content-Length: 51

{"temperature": 25, "humidity": 56, "pressure": 63}

As you can see above, the request is posting to the host and to end-point /api/v1.6/devices/{API_LABEL_FOR_DEVICE}/?token={YOUR_UBIDOTS_TOKEN}. Here you will assign your own API Label for the intended device name within your Ubidots account. Conversely the API Labels for variables are included in the payload of the request - as shown above, the payload is {"temperature": 25, "humidity": 56, "pressure": 63} where the API Labels have been provisioned as "temperature," "humidity," and "pressure."

Example Request:

curl -X POST -H "Content-Type: application/json" -d '{"temperature": 25, "humidity": 56, "pressure": 63}' ""

Request Response:

    "pressure": [{"status_code": 201}],
    "temperature": [{"status_code": 201}],
    "humidity": [{"status_code": 201}]

Please note that if a device with API label = "new-device" does not exist in your account, a new device with 3 variables temperature, humidity and pressure will be automatically created in your account. If the device with the API Label "my-new-device" already exists, the data POST to the already existing device in your account. More details can be found here.

In this article we have explained the usefulness of API Labels and the time saving value this firmware development adds to your deployment. With a simple POST request, you can launch Devices and Variables in an Ubidots account without requiring any additional application configurations.

If you are deploying a large IoT solution and have several devices, the API labels will make your life a lot easier. You can customize your firmware to get the MAC address of each device and assign it as Device API Label making sure that it is unique in your Ubidots account.

To test your deployment speed and capabilities, check out Ubidots and take advantage of the Free 30-Day Trial to integrate your connected solutions with ease. 

Other users also found useful: 

Did this answer your question?