No Data from influxDB query

Hi,

I’m quite new to influxdb and I’m trying to get data from Postman without much of success although from influxdb I get data.

In InfluxDB the query I’m executing is:

from(bucket: "ttn_data")
  |> range(start: -30d)
  |> filter(fn: (r) => r["_measurement"] == "mqtt_consumer")
  |> filter(fn: (r) => r["_field"] == "BME680_breath_voc_eq")

while from Postman I have the url: http://localhost::8086/api/v2/query/analyze?orgID=myorg and in headers I have:

Accept: application/json
Content-Type: application/json
Body: raw

{

"query": "from(bucket: \"ttn_data\") \n |> range(start: -30d) \n |> filter(fn: (r) => r[\"_measurement\"] == \"mqtt_consumer\") \n |> filter(fn: (r) => r[\"_field\"] == \"BME680_breath_voc_eq\")",

"type": "flux"

}

The result of the query is 200 OK:

{
    "errors": []
}

In the logs of influxdb I receive:

influxdb_1  | ts=2022-04-05T22:21:31.957352Z lvl=debug msg="user find by ID" log_id=0_fwX6iW000 store=new took=0.046ms
influxdb_1  | ts=2022-04-05T22:21:31.962078Z lvl=debug msg=Request log_id=0_fwX6iW000 service=http method=POST host=localhost:8086 path=/api/v2/query/analyze query="orgID=iot" proto=HTTP/1.1 status_code=200 response_size=14 content_length=353 referrer= remote=172.21.0.1:34270 user_agent=PostmanRuntime took=4.868ms body="{\n\"query\": \"from(bucket: \\\"ttn_data\\\") \\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop) \\n |> filter(fn: (r) => r[\\\"_measurement\\\"] == \\\"mqtt_consumer\\\") \\n |> filter(fn: (r) => r[\\\"_field\\\"] == \\\"BME680_breath_voc_eq\\\") \\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false) \\n |> yield(name: \\\"mean\\\")\",\n\"type\": \"flux\"\n}"

Am I missing something?

Thanks

Hello,
This might be helpful:

Here’s what my cURL request from postman looks like:

curl --location --request POST 'https://us-west-2-1.aws.cloud2.influxdata.com/api/v2/query/analyze?orgID=<myorgID>' \
--header 'Accept: application/json' \
--header 'Authorization: Token <mytoken>' \
--header 'Content-Type: application/json' \
--data-raw '{
"query": "from(bucket: \"Jetson\")\n  |> range(start: 1h)\n  |> filter(fn: (r) => r[\"_measurement\"] == v.measurments)\n  |> filter(fn: (r) => r[\"_field\"] == \"jetson_Temp AO\" or r[\"_field\"] == \"jetson_Temp CPU\" or r[\"_field\"] == \"jetson_Temp GPU\" or r[\"_field\"] == \"jetson_Temp PLL\" or r[\"_field\"] == \"jetson_Temp thermal\")\n  |> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)\n  |> yield(name: \"last\")"
}'

@Symeon_Mattes what you have looks good. Maybe try not specifying the query type in the body?

Without the type I receive:

{
    "code": "internal error",
    "message": "An internal error has occurred - check server logs"
}

I find it weird, because in PostQuery it mentions that query is required while type is not. However it seems as if “query” key is not required because if I use this as body:

{
"type": "flux"
}

I receive again 200 OK:


{
    "errors": []
}

Thanks for the tutorial…I already know it and I’m using it as it recommends. I have tried it with curl and I receive the same results.

I found the issue. Actually the Postman Collection has a misguided configuration. To retrieve data you need:

{{base_url}}/api/v2/query?orgID={{orgID}}

Then one I was using was

http://localhost::8086/api/v2/query/analyze?orgID={{orgID}}

which is for analyzing the query