Help with receiving data from influxdb

I try to get Test item state from influxdb.
This script works ok, but maybe easier way exists?

curl -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d `curl -GET 'http://openhab:openhab@localhost:8086/query?db=openhab_db' --data-urlencode 'q=select last(ppm) from co2 where time > now() - 2h'` "http://localhost:8080/rest/items/Test/state"

Result:

[{"statement_id":0,"series":[{"name":"co2","columns":["time","last"],"values":[["2017-04-02T19:14:50.204Z",454]]}]}]}

It works from console, but not work from rules.
I try it with sudo -u openhab - its ok.

First question is: What’s the purpose to manually request influxdb?

If openHAB writes the data, you could use
MyItem.historicState(time).state or MyItem.avarageSince(time)

where time is something like now.minusHours(2) or another joda string.

This would be used from within openHAB rules, e.g. to set other items.

I have a co2 sensor and its software post data directly to influxdb.
And i need to get latest value ppm from co2 table.