# API method to return all variables with their values

**URL:** <https://community.particle.io/t/api-method-to-return-all-variables-with-their-values/4683>\
**Category:** Cloud\
**Created:** [May 29, 2014, 12:08am UTC](https://community.particle.io/t/api-method-to-return-all-variables-with-their-values/4683 "2014-05-29T00:08:52Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![sej7278](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@sej7278](https://community.particle.io/u/sej7278)\
**Post date:** [May 29, 2014, 12:08am UTC](https://community.particle.io/t/api-method-to-return-all-variables-with-their-values/4683/1 "2014-05-29T00:08:52Z")

</div>

I know we can use:

[https://api.spark.io/v1/devices/{DEVICE\_ID}/{VARIABLE}?access\_token={ACCESS\_TOKEN}](https://api.spark.io/v1/devices/%7BDEVICE_ID%7D/%7BVARIABLE%7D?access_token=%7BACCESS_TOKEN%7D)

to get a single variable, and:

[https://api.spark.io/v1/devices/{DEVICE\_ID}/?access\_token={ACCESS\_TOKEN}](https://api.spark.io/v1/devices/%7BDEVICE_ID%7D/?access_token=%7BACCESS_TOKEN%7D)

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.

---

<div class="post-metadata">

**Author:** ![wgbartley](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/wgbartley/32/1910_2.png) [@wgbartley](https://community.particle.io/u/wgbartley)\
**Post date:** [May 29, 2014, 4:22am UTC](https://community.particle.io/t/api-method-to-return-all-variables-with-their-values/4683/2 "2014-05-29T04:22:40Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sej7278](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@sej7278](https://community.particle.io/u/sej7278)\
**Post date:** [May 29, 2014, 8:46am UTC](https://community.particle.io/t/api-method-to-return-all-variables-with-their-values/4683/3 "2014-05-29T08:46:48Z")

</div>

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! 😉

---

<div class="post-metadata">

**Author:** ![bko](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bko/32/20704_2.png) [@bko](https://community.particle.io/u/bko)\
**Post date:** [May 29, 2014, 11:13am UTC](https://community.particle.io/t/api-method-to-return-all-variables-with-their-values/4683/4 "2014-05-29T11:13:40Z")

</div>

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.

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

```

---

<div class="post-metadata">

**Author:** ![wgbartley](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/wgbartley/32/1910_2.png) [@wgbartley](https://community.particle.io/u/wgbartley)\
**Post date:** [May 29, 2014, 2:24pm UTC](https://community.particle.io/t/api-method-to-return-all-variables-with-their-values/4683/5 "2014-05-29T14:24:49Z")

</div>

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](https://community.spark.io/t/keeping-binary-states-with-integers/4074). 😄

---

<div class="post-metadata">

**Author:** ![sej7278](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@sej7278](https://community.particle.io/u/sej7278)\
**Post date:** [May 29, 2014, 2:54pm UTC](https://community.particle.io/t/api-method-to-return-all-variables-with-their-values/4683/6 "2014-05-29T14:54:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zachary](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/zachary/32/20717_2.png) [@zachary](https://community.particle.io/u/zachary)\
**Post date:** [June 7, 2014, 10:53pm UTC](https://community.particle.io/t/api-method-to-return-all-variables-with-their-values/4683/7 "2014-06-07T22:53:32Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![picitup](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@picitup](https://community.particle.io/u/picitup)\
**Post date:** [September 5, 2015, 8:22pm UTC](https://community.particle.io/t/api-method-to-return-all-variables-with-their-values/4683/8 "2015-09-05T20:22:17Z")

</div>

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}](https://api.spark.io/v1/devices/%7BDEVICE_ID%7D/?access_token=%7BACCESS_TOKEN2%7D)

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

---

<div class="post-metadata">

**Author:** ![luckroy](https://avatars.discourse-cdn.com/v4/letter/l/c57346/32.png) [@luckroy](https://community.particle.io/u/luckroy)\
**Post date:** [February 19, 2016, 4:51pm UTC](https://community.particle.io/t/api-method-to-return-all-variables-with-their-values/4683/9 "2016-02-19T16:51:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zachary](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/zachary/32/20717_2.png) [@zachary](https://community.particle.io/u/zachary)\
**Post date:** [April 28, 2016, 1:40am UTC](https://community.particle.io/t/api-method-to-return-all-variables-with-their-values/4683/10 "2016-04-28T01:40:58Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Cameron](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/cameron/32/9238_2.png) [@Cameron](https://community.particle.io/u/Cameron)\
**Post date:** [January 7, 2017, 2:32pm UTC](https://community.particle.io/t/api-method-to-return-all-variables-with-their-values/4683/11 "2017-01-07T14:32:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Cameron](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/cameron/32/9238_2.png) [@Cameron](https://community.particle.io/u/Cameron)\
**Post date:** [January 7, 2017, 2:36pm UTC](https://community.particle.io/t/api-method-to-return-all-variables-with-their-values/4683/12 "2017-01-07T14:36:34Z")

</div>

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
