DEV Community

Francesco Tisiot
Francesco Tisiot

Posted on • Originally published at ftisiot.net

How to query remote InfluxDB via cURL

Terminal showing the cURL code to query InfluxDB

Sometimes you want to query a remote InfluxDB server to understand the data in it. This can be done via cURL as explained in the InfluxDB docs

Parameters

  • HOSTNAME: Database hostname
  • PORT: Database port
  • PROTOCOL: Protocol to connect to the database HTTPS, HTTP
  • USERNAME: Username to connect to the database
  • PASSWORD: Password to connect to the database
  • DB_NAME: Database name
  • QUERY_STR: Query string to be exectuted. The query string needs to be properly escaped, e.g. SELECT \"ts_ms\" FROM \"test_measurement\"

cURL Query Code

Execute the following by replacing the parameters above

curl -G 'https://<USERNAME>:<PASSWORD>@<HOSTNAME>:<PORT>/query?pretty=true' \ --data-urlencode "db=<DB_NAME>" \ --data-urlencode "q=<QUERY_STR>" 
Enter fullscreen mode Exit fullscreen mode

As example to get the SELECT \"ts_ms\" FROM \"test_measurement\" you can run:

curl -G 'https://<USERNAME>:<PASSWORD>@<HOSTNAME>:<PORT>/query?pretty=true' \ --data-urlencode "db=<DB_NAME>" \ --data-urlencode "q=SELECT \"ts_ms\" FROM \"test_measurement\"" 
Enter fullscreen mode Exit fullscreen mode

Results:

{ "results": [ { "statement_id": 0, "series": [ { "name": "TEST", "columns": [ "time", "ts_ms" ], "values": [ [ "2022-11-07T08:50:20.772317361Z", 1667809412536 ], [ "2022-11-07T08:50:20.789690226Z", 1667809412547 ], [ "2022-11-07T08:50:20.79052872Z", 1667809412548 ], [ "2022-11-07T08:51:53.165095297Z", 1667811112824 ], ] } ] } ] } 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)