Node-red-contrib-influxdb specifying parameters in a function node

Hi, I'm using node-Red (V2.0.3) to write to an Influx server (1.8.10) with two databases using this contrib. Writing the data is going Ok but I'm being stumped by writing a node-Red function to query the timestamp of the last measurements (PT1H) in a database (energy).

I've managed to get the output I want using cURL (my specific credentials etc have been replaced by capitalised words):
curl -G http://MYINFLUXDB:8086/query?db=energy -H 'Accept:application/csv' -H 'Content-type:application/vnd.flux' -H 'Authorization: Token MYINFLUXUSER:MYINFLUXUSERPASSWORD' --data-urlencode 'q=SELECT * from PT1H order by time desc limit 1'

I've put the relevant sections into a function node (see below) which feeds into an Influxdb In node configured for my Influxdb [1.8 flux] server:

msg.database = "energy"
msg.query=`SELECT * from PT1H order by time desc limit 1`
msg.headers = {};
msg.headers['accept'] = "Accept:application/csv";
msg.headers['Content-type'] = "application/vnd.flux";
msg.headers['Authorization'] = "Token MYINFLUXUSER:MYINFLUXUSERPASSWORD"
return msg;

I think the query and headers bits are Ok but not sure about where/how to specify the database in the function node. I keep getting an error from the server:

HttpError: 500 Internal Server Error : {"error":"type error 1:1-1:7: undefined identifier \"SELECT\""}

It may be that all of my function node is wrong, but I'd appreciate any pointers on how to get this working.

Using the Influx In node you don't need anything in the message you pass to the node except msg.query. Tell it which database to use in the Server config (click the pen to the right of the Server field. Also setup the access credentials in there.
Set the Version to 1.x as I assume you are using influx 1.8 and not using the Flux query language.

@Colin thanks for the response. The access credentials are already in the Server config as you say, so although they were necessary for the cURL, they are not needed in the message header. However, the Influxdb In Node doesn't have anywhere to specify the database ("energy" in my case), screenshot below.


I know the Influxdb Out node does have somewhere to specify the database and the measurement (although the measurement can also be specified in the message object), but that doesn't seem to have a means of responding to a query.
I'd be happy for you correct me if I've got this wrong but I'm still stumped.

It is in the Server config. Also I note you still have 1.8-flux selected. As I said before, you are not using the Flux query language so you must select 1.x.

The measurement is in the query.

@Colin you are right. I've changed the server to 1.x and included the database name there and the query now runs. It's confusing that v1.8.10 database needs 1.x rather than 1.8 server specifying in the node. I used the 1.8 specification to write all my data points, which seem to have gone in fine.

1.x means any 1.x, not using the Flux query language, so that includes 1.8.
If you want to use the Flux query language that is only supported by 1.8 and 2.0 so for those you can use 1.8-flux or 2.0-flux.

In fact the error you were getting was probably because it was trying to interpret your query as a Flux query instead of InfluxQL.

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