# How to get devices + attribute values

**URL:** <https://forums.losant.com/t/how-to-get-devices-attribute-values/3985>\
**Category:** Help\
**Tags:** rest-api\
**Created:** [August 6, 2021, 8:56pm UTC](https://forums.losant.com/t/how-to-get-devices-attribute-values/3985 "2021-08-06T20:56:31Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nigel\_Reed](https://avatars.discourse-cdn.com/v4/letter/n/71c47a/32.png) [@Nigel\_Reed](https://forums.losant.com/u/Nigel_Reed)\
**Post date:** [August 6, 2021, 8:56pm UTC](https://forums.losant.com/t/how-to-get-devices-attribute-values/3985/1 "2021-08-06T20:56:31Z")

</div>

Hi all,

I would like to fetch a list of all devices along with a couple of their attributes, namedly cputemp and cpuload but unsure how to accomplish this.

I can get the devices ok but unsure how to specify which attributes to fetch also, if it’s even possible.

Can anyone lend a hand on how to create a query to achieve this?

Thanks,  
Nigel

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [August 6, 2021, 9:01pm UTC](https://forums.losant.com/t/how-to-get-devices-attribute-values/3985/3 "2021-08-06T21:01:07Z")

</div>

Hey @Nigel_Reed,

When using the [Device: Get Node](https://docs.losant.com/workflows/data/get-device/), you can choose to [include Composite State](https://docs.losant.com/workflows/data/get-device/#result-path) for those devices. You can do this in the Node Configuration by selecting the drop-down for “Composite State to Include”, and selecting “Include the Following Attributes”, as seen here:  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/f/f883391fc1582eec4468a438c598b72221a02f60.png)

Then you will be able to select which attributes you would like returned. 🙂

Please let me know if this works for you!

Thank you,  
Heath

---

<div class="post-metadata">

**Author:** ![Nigel\_Reed](https://avatars.discourse-cdn.com/v4/letter/n/71c47a/32.png) [@Nigel\_Reed](https://forums.losant.com/u/Nigel_Reed)\
**Post date:** [August 9, 2021, 3:19pm UTC](https://forums.losant.com/t/how-to-get-devices-attribute-values/3985/5 "2021-08-09T15:19:37Z")

</div>

Doh. I forgot to mention I’m using the API for this. Will that still be required in the workflow?

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [August 9, 2021, 3:55pm UTC](https://forums.losant.com/t/how-to-get-devices-attribute-values/3985/7 "2021-08-09T15:55:52Z")

</div>

Hey @Nigel_Reed,

No problem at all!

There is not currently an API endpoint that will get you exactly what you’re looking for. You can try the [Last Value Query](https://docs.losant.com/rest-api/data/#last-value-query) endpoint. This will get you the last value reported for a single attribute for multiple devices.

Could you tell me a bit more about your use case and what you’re using the API for? Are you running your own, custom software? I’d love to hear more about how you’re using Losant!

Thank you,  
Heath

---

<div class="post-metadata">

**Author:** ![Nigel\_Reed](https://avatars.discourse-cdn.com/v4/letter/n/71c47a/32.png) [@Nigel\_Reed](https://forums.losant.com/u/Nigel_Reed)\
**Post date:** [August 9, 2021, 4:08pm UTC](https://forums.losant.com/t/how-to-get-devices-attribute-values/3985/9 "2021-08-09T16:08:40Z")

</div>

If you drop me an email, I’ll be happy to discuss. I wouldn’t want to do so in public due to customer confidentiality.

What I am trying to do it produce current cpu load and temperatures for all our devices that can be generated using the API so I can script and sort/filter the report manually.

---

<div class="post-metadata">

**Author:** ![Nigel\_Reed](https://avatars.discourse-cdn.com/v4/letter/n/71c47a/32.png) [@Nigel\_Reed](https://forums.losant.com/u/Nigel_Reed)\
**Post date:** [August 9, 2021, 6:24pm UTC](https://forums.losant.com/t/how-to-get-devices-attribute-values/3985/11 "2021-08-09T18:24:10Z")

</div>

Unfortunately, I can’t get that to work. I went back to basics and tried the CURL example:

curl -H ‘Content-Type: application/json’   
-H ‘Accept: application/json’ -H ‘Authorization: Bearer blahblah’   
-X POST   
-d ‘{“attribute”:“cpuTemp”}’ \ [https://api.losant.com/applications/myid/data/last-value-query](https://api.losant.com/applications/myid/data/last-value-query)

I get nothing.

When I use the devices endpoint, I can see

‘attributes’ =\> [  
…snip…  
{  
‘name’ =\> ‘cpuTemp’,  
‘dataType’ =\> ‘number’,  
‘description’ =\> ‘’,  
‘attributeTags’ =\> {}  
} },

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [August 9, 2021, 6:27pm UTC](https://forums.losant.com/t/how-to-get-devices-attribute-values/3985/12 "2021-08-09T18:27:49Z")

</div>

Hey @Nigel_Reed,

Looking at what you pasted in, it looks like you might not have included `deviceIds` in your request.

From the example in the docs:

```auto
curl -H 'Content-Type: application/json' \
    -H 'Accept: application/json' \
    -H 'Authorization: Bearer YOUR_API_ACCESS_TOKEN' \
    -X POST \
    -d '{"deviceIds":["575ecf887ae143cd83dc4aa2","575ef5c97ae143cd83dc4aac"],"attribute":"voltage"}' \
    https://api.losant.com/applications/APPLICATION_ID/data/last-value-query

```

Thanks,  
Heath

---

<div class="post-metadata">

**Author:** ![Nigel\_Reed](https://avatars.discourse-cdn.com/v4/letter/n/71c47a/32.png) [@Nigel\_Reed](https://forums.losant.com/u/Nigel_Reed)\
**Post date:** [August 9, 2021, 7:02pm UTC](https://forums.losant.com/t/how-to-get-devices-attribute-values/3985/13 "2021-08-09T19:02:05Z")

</div>

I can’t provide 6000+ device id’s. That’s not feasible. I didn’t see anything that states device id’s are mandatory. You’d think if not specified then everything would be returned.

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [August 9, 2021, 8:05pm UTC](https://forums.losant.com/t/how-to-get-devices-attribute-values/3985/14 "2021-08-09T20:05:20Z")

</div>

First things first - the [`data.lastValueQuery`](https://docs.losant.com/rest-api/data/#last-value-query) endpoint will only return a maximum of 1,000 devices in a single call, whether you pass device IDs or device tags, and that endpoint does not have any pagination features built into it. So if you need 6,000 devices in a single response, that will not work for your use case. Instead, it would require multiple, carefully constructed API calls (as outlined below).

Instead of passing an array of device IDs, pass an array of deviceTags instead. This would require every device you want to retrieve data for to have a common key (but not necessarily a common value). For example …

```json
{
  "deviceTags": [{"key": "myKey"}]
}

```

would return an entry for each device that had a tag with a key of “myKey” regardless of the tag’s value.

In your case, you would need some sort of tag value grouping mechanism to break the devices up in chunks of 1,000 or less, so you would want to tag, say, 800 devices with “myKey=1”, and the next 800 with “myKey=2”, and so on, constructing your tag query as …

```json
{
  "deviceTags": [{"key": "myKey", "value": "1"}]
}

```

If your use case allows it, you could make a single call to the [`data.export`](https://docs.losant.com/rest-api/data/#export) endpoint that would send all device data and a selection of attributes to either a callback URL or an email address, but it would be on you to wait for that result, download and parse the CSV, and take whatever action you need that data for in your application.

I did make a feature request to allow for returning composite state through the devices.get endpoint (similar to how the Device: Get Node works) and will let you know if it is selected for development and is completed. Bear in mind that would be a paginated endpoint, so you still wouldn’t get 6,000+ devices in a single API call.

---

<div class="post-metadata">

**Author:** ![Nigel\_Reed](https://avatars.discourse-cdn.com/v4/letter/n/71c47a/32.png) [@Nigel\_Reed](https://forums.losant.com/u/Nigel_Reed)\
**Post date:** [August 9, 2021, 8:42pm UTC](https://forums.losant.com/t/how-to-get-devices-attribute-values/3985/15 "2021-08-09T20:42:12Z")

</div>

Yeah, the data export really defeats the purpose of accessing via the API.

I use another API where I have results paginated so I already have routines to handle that sort of situation.

If the composite state gets developed, that would be useful, especially if it could be filtered. I’ll keep an eye out.

Thanks,  
Nigel

---

<div class="post-metadata">

**Author:** ![Nigel\_Reed](https://avatars.discourse-cdn.com/v4/letter/n/71c47a/32.png) [@Nigel\_Reed](https://forums.losant.com/u/Nigel_Reed)\
**Post date:** [August 30, 2021, 4:01pm UTC](https://forums.losant.com/t/how-to-get-devices-attribute-values/3985/17 "2021-08-30T16:01:25Z")

</div>

I did want to swing around and let you know I got the data.lastValueQuery working using the deviceTags.

I’ll watch out for an update regarding your enhancement request.

Thanks,  
Nigel

---

<div class="post-metadata">

**Author:** ![Nigel\_Reed](https://avatars.discourse-cdn.com/v4/letter/n/71c47a/32.png) [@Nigel\_Reed](https://forums.losant.com/u/Nigel_Reed)\
**Post date:** [October 28, 2021, 4:29pm UTC](https://forums.losant.com/t/how-to-get-devices-attribute-values/3985/20 "2021-10-28T16:29:17Z")

</div>

Team,

All queries to losant are receiving a timeout. Our EMM platform is showing

```auto
{ "error": "Time out waiting for workflow reply" }

```

When trying to refresh deployment status I get a time out.

This is obviously affecting production and needs urgent attention please.

Thanks,  
Nigel

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [October 28, 2021, 4:31pm UTC](https://forums.losant.com/t/how-to-get-devices-attribute-values/3985/21 "2021-10-28T16:31:24Z")

</div>

Our team is investigating currently. You can track the status of the partial outage at [https://status.losant.com](https://status.losant.com). The outage is also mentioned at the top of the web interface.

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [October 28, 2021, 5:17pm UTC](https://forums.losant.com/t/how-to-get-devices-attribute-values/3985/22 "2021-10-28T17:17:50Z")

</div>

We’ve put a fix in place and are monitoring the situation. The platform is operational again and you should not be experiencing any issues. (Please let us know if you do.)

[https://status.losant.com/](https://status.losant.com/)

Thanks again for your patience.

---

<div class="post-metadata">

**Author:** ![Nigel\_Reed](https://avatars.discourse-cdn.com/v4/letter/n/71c47a/32.png) [@Nigel\_Reed](https://forums.losant.com/u/Nigel_Reed)\
**Post date:** [October 28, 2021, 7:44pm UTC](https://forums.losant.com/t/how-to-get-devices-attribute-values/3985/23 "2021-10-28T19:44:42Z")

</div>

Not sure how this outage got on an old question of mine, but it is broken again.

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [October 28, 2021, 7:54pm UTC](https://forums.losant.com/t/how-to-get-devices-attribute-values/3985/24 "2021-10-28T19:54:30Z")

</div>

Nigel,

Thank you for letting us know. Our team is investigating and working to implement a fix.

As @Dylan_Schuster mentioned, you can keep an eye on our [status page](https://status.losant.com) to track this outage.

I will follow up with you as soon as I have an update.

Thank you,  
Heath

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [October 28, 2021, 8:16pm UTC](https://forums.losant.com/t/how-to-get-devices-attribute-values/3985/25 "2021-10-28T20:16:18Z")

</div>

@Nigel_Reed,

A fix has been implemented and you should be able to use Losant as you normally would.

We are continuing to monitor the platform as our team works to implement a long-term solution.

Thank you for your patience and communication.

Heath

---

<div class="post-metadata">

**Author:** ![Sebastian\_Turner](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/sebastian_turner/32/4024_2.png) [@Sebastian\_Turner](https://forums.losant.com/u/Sebastian_Turner)\
**Post date:** [July 31, 2023, 5:23pm UTC](https://forums.losant.com/t/how-to-get-devices-attribute-values/3985/26 "2023-07-31T17:23:06Z")

</div>

Hi @Nigel_Reed ,

Just wanted to follow up on this thread and let you know that with our [most recent platform update](https://www.losant.com/blog/edge-custom-nodes-notebook-usage-tracking), we’ve published a new [Devices: Get Composite State](https://docs.losant.com/rest-api/devices/#get-composite-state) API endpoint, which can be used to retrieve the last reported value of one or more attributes for a collection of devices. Please let us know if you have any questions!
