# Retrieve influxdb with Nodered

**URL:** <https://discourse.nodered.org/t/retrieve-influxdb-with-nodered/40882>\
**Category:** Dashboard\
**Created:** [12 February 2021 17:40 UTC](https://discourse.nodered.org/t/retrieve-influxdb-with-nodered/40882 "2021-02-12T17:40:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jfabernathy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jfabernathy/32/34883_2.png) [@jfabernathy](https://discourse.nodered.org/u/jfabernathy)\
**Post date:** [12 February 2021 17:40 UTC](https://discourse.nodered.org/t/retrieve-influxdb-with-nodered/40882/1 "2021-02-12T17:40:46Z")

</div>

I'm trying to retrieve the most recent 2 items from InfluxDB via Nodered for further processing. I can't seem to combine the items and get the last values.  
This works:  
SELECT last(Temperature) FROM environment where Location = '5th\_wheel'  
but it only returns one value.

This works but gets the oldest readings:  
select "Temperature", "Humidity" FROM environment WHERE Location = '5th\_wheel' LIMIT 1

This draws an error:  
select last("Temperature", "Humidity") FROM environment WHERE Location = '5th\_wheel'  
"Error: Error from InfluxDB: invalid number of arguments for last, expected 1, got 2"

Not sure if this worked because the timecode is wrong:  
select last("Temperature"), last("Humidity") FROM environment WHERE Location = '5th\_wheel'

0: object  
time: "1970-01-01T00:00:00.000Z"  
last: 39  
last\_1: 66.2

Any idea of what the right query would be??

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 February 2021 17:56 UTC](https://discourse.nodered.org/t/retrieve-influxdb-with-nodered/40882/2 "2021-02-12T17:56:47Z")

</div>

`order by time desc limit 2`  
Or something like that. Check the docs if it isn't quite right.

---

<div class="post-metadata">

**Author:** ![jfabernathy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jfabernathy/32/34883_2.png) [@jfabernathy](https://discourse.nodered.org/u/jfabernathy)\
**Post date:** [12 February 2021 18:25 UTC](https://discourse.nodered.org/t/retrieve-influxdb-with-nodered/40882/3 "2021-02-12T18:25:19Z")

</div>

Thanks that got me on the right track.  
`select "Temperature", "Humidity" FROM environment WHERE Location = '5th_wheel' order by time desc limit 1`

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 February 2021 18:48 UTC](https://discourse.nodered.org/t/retrieve-influxdb-with-nodered/40882/4 "2021-02-12T18:48:35Z")

</div>

> [@jfabernathy](#):
>
> limit 1

You said you wanted two.

---

<div class="post-metadata">

**Author:** ![jfabernathy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jfabernathy/32/34883_2.png) [@jfabernathy](https://discourse.nodered.org/u/jfabernathy)\
**Post date:** [12 February 2021 18:52 UTC](https://discourse.nodered.org/t/retrieve-influxdb-with-nodered/40882/5 "2021-02-12T18:52:05Z")

</div>

2 values, temperature and humidity, but the most recent

---

<div class="post-metadata">

**Author:** ![jfabernathy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jfabernathy/32/34883_2.png) [@jfabernathy](https://discourse.nodered.org/u/jfabernathy)\
**Post date:** [12 February 2021 19:42 UTC](https://discourse.nodered.org/t/retrieve-influxdb-with-nodered/40882/6 "2021-02-12T19:42:52Z")

</div>

Now that I have the query working in Nodered for my influxDB data, I need to build the http request part of it. I can't find the right example online. I want to use [http://192.168.0.25:1880/basement](http://192.168.0.25:1880/basement) to retrieve the most recent basement temperature and humidity reading from the influxDB and return those readings in a JSON string. Once I have this working I can change up the basement for another location that will be used as part of the query. (FYI, the data in the influxDB is updated once a minute via MQTT nodes in various locations.)

Any ideas on how to manage this?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 February 2021 21:11 UTC](https://discourse.nodered.org/t/retrieve-influxdb-with-nodered/40882/7 "2021-02-12T21:11:28Z")

</div>

Start by looking at the http examples in the node red cookbook.

Then best to start a new thread if necessary with an appropriate subject line.

---

<div class="post-metadata">

**Author:** ![jfabernathy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jfabernathy/32/34883_2.png) [@jfabernathy](https://discourse.nodered.org/u/jfabernathy)\
**Post date:** [12 February 2021 21:15 UTC](https://discourse.nodered.org/t/retrieve-influxdb-with-nodered/40882/8 "2021-02-12T21:15:46Z")

</div>

found an example

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 February 2021 21:16 UTC](https://discourse.nodered.org/t/retrieve-influxdb-with-nodered/40882/9 "2021-02-26T21:16:17Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
