1
votes

I am using the REST API of InfluxDB

curl -s -XPOST -G influxdb_url:8086/query?pretty=true --data-urlencode "db=metrics" --data-urlencode "q=SHOW MEASUREMENTS WITH MEASUREMENT=~/a.b-c*/"

to retrieve the measurements available

    {
    "results": [
        {
            "statement_id": 0,
            "series": [
                {
                    "name": "measurements",
                    "columns": [
                        "name"
                    ],
                    "values": [
                        [
                            "a.b-c"
                        ],
                        [
                            "a.b-cd"
                        ],
                        [
                            "a.b-cde"
                        ],
                        [
                            "a.b-cdfg"
                        ]
                    ]
                }
            ]
        }
    ]
}

and then I trying to select all the data from one of them

curl -s -XPOST -G influxdb_url:8086/query?pretty=true --data-urlencode "db=metrics" --data-urlencode "q=SELECT * FROM "a.b-c""

and I am getting this error

{
    "error": "error parsing query: found -, expected ; at line 1, char 18"
}

The exact same query works if I login the Influx instance

select * from "a.b-c"
1

1 Answers

2
votes

The issue here is the use of the quotation mark " in the string where you specify your query. To properly include the quotation mark in your query you need to wrap the string in triple single quotes. In this particular case the correct way is the following:

curl -s -XPOST -G influxdb_url:8086/query?pretty=true --data-urlencode "db=metrics" --data-urlencode '''q=SELECT * FROM "a.b-c"''' 

which in turn gives you a desired outcome. An example of a response using test dataset:

{
    "results": [
        {
            "statement_id": 0,
            "series": [
                {
                    "name": "a.b-c",
                    "columns": [
                        "time",
                        "m",
                        "value"
                    ],
                    "values": [
                        [
                            "2020-10-06T15:13:29.562248587Z",
                            "a",
                            0
                        ]
                    ]
                }
            ]
        }
    ]
}