API method to return all variables with their values

I know we can use:

https://api.spark.io/v1/devices/{DEVICE_ID}/{VARIABLE}?access_token={ACCESS_TOKEN}

to get a single variable, and:

https://api.spark.io/v1/devices/{DEVICE_ID}/?access_token={ACCESS_TOKEN}

to get all variable names/types and functions, but is there a URL for getting the values of all the variables too?

i’d rather a single request that returns name/values pairs i can iterate through to make an array/hash, rather than a bunch of urls to parse individually.

3 Likes

I don’t think there’s a method that will let you do that. However, it’s definitely not a bad idea. Maybe @Dave and @zachary can comment more on it and add it to the backlog?

how odd. this was my first time at using the api functions and “how do i get name/value pairs?” was the first thing i thought of, surely people aren’t calling 2 url’s just to get temperature and pressure from barometric sensors?

hey i just halved (at least) the load on your servers! :wink:

You can return strings with multiple values in them. You just have to be mindful of the 64 character limit.

In my Spark.publish() with JSON tutorial I do this to make string to send. You could do this with Spark.variable() just as well.

sprintf(publishString,"{\"Hours\": %u, \"Minutes\": %u, \"Seconds\": %u}",hours,min,sec);
1 Like

That’s how I usually do multiple values if I need to.

If you are keeping several binary states (on/off, true/false, 1/0), you can try Keeping Binary States with Integers. :smile:

yup, i do that with pi/avr stuff (even comma delimited for easy import) i just thought it odd that we have name/type but not name/value for debugging.

Interesting interesting… good thought @sej7278. The important difference between those two calls is that the list of variable names exposed by a Core is cached in the Cloud, so GET /v1/devices/:id can list them without actually hitting the Core. However, getting the value of a variable obviously does require communication with the device.

On the other hand, the encrypted CoAP communication is miniscule in comparison to the HTTPS request on the API side, so adding some way to do this in a single API request is a good idea. I’ve added it to our backlog. Thanks for the suggestion!

4 Likes

I was wondering if there had been any progress on this? If it was easy for you to code, I’d rather the request:

https://api.spark.io/v1/devices/{DEVICE_ID}/?access_token={ACCESS_TOKEN2}

Returns variables and values, rather than variables and data types. If you have 20 variables on a page, you really don’t want to do 20 requests as your app will be so slooooowwww…

Just my 2 pennorth…

Steve

1 Like

Sorry to gravedig this thread, but I’m also looking for an update on this. I’d like to gather multiple variables for ingestion into InfluxDB and being able to get them all in a single request as native data values (i.e. not encoded into a string) would be very helpful.

No changes here yet, but I’ll bump it again in our backlog. We have a lot to accomplish, and without more community validation, I don’t expect this will get built anytime soon. Keep letting us know your needs and desires though. The more suggestions from the community the better!

Spent half a day today, only to realise it wasn’t my code throwing errors… but the API providing data types not values… sigh. Wish I had read this first

Would be great to see this feature!

The system we are building is going to read a range of values from multiple sensors, sometimes we will not know which sensors are active on the device. It’s a bit of a pain to have our servers running repeated requests for sensors that may not be connected to the device.

Plus the coding overhead to do multiple calls and maintain them as we develop is tedious.

Hope you can bump this one up the ladder