I need to get 3 variable values from each device into client side code. I have a cloud function that the code hits and returns all the devices that I then parse out the variable URL’s from and hit the API again requesting each variables value. I have about 300 devices and this equals quite a few API requests. Is there a way to do this with one HTTP request?
Im not quite sure if you already mean what I am suggesting when you refer to ‘cloud function’ but I have a similar requirement whereby I need data from multiple devices delivered via one HTTP request and solved it by using the Ubidots functions to create a single endpoint to request from and that function did all the hard work of requesting data from the individual devices, packaging it all up into a single JSON object and returning that.
It was really to simplify the call. All the info from a device’s variables and some decoded info held in the device properties was wrapped up in a single JSON object returned by the single call to the Ubidots function.
Looking at it now this was a single device and do not have speed issues but getting info from the function should not be slower than if you asked for data from each device from a browser.
There is a double hop so that adds an overall latency but that would get less noticeable the more devices you got data from in the function.
The most optimal way of retrieving the variable data for multiple variables I believe is the Data Raw Series endpoint. From this endpoint you can specify a list of variable IDs, a start and end timestamp top get the values from, and other special information that might be of interest (view the API Docs for better reference).
Note: if start and end timestamps aren’t provided, the request will return the variable’s last 100 values. To limit the amount of values retrieved for each variable, use the "limit" key parameter within the body of the request. For example, to get the last 5 values of each variable, then the body would be: