Influx 2.1 CLI on Windows Powershell

Hi all,

I’ve got some issues using the influx CLI within the Windows Powershell. I successfully set my credentials and I’m able to connect to the database. Manual insertation has also worked fine and I can use “.\influx bucket list” to make sure that the connection is established and buckets are available.

However, Flux-queries of the form:
.\influx.exe query ‘from(bucket:“ExBucket”) |> range(start:-1y)’
always abort with the following error message:
Error: failed to execute query: 400 Bad Request: error @1:13-1:22: undefined identifier ExBucket

I supposed problems with the quotation marks and tried different formats (like ´" or “” to escape the quotation mark within the string), unfortunately without success.

Any suggestions?

Thanks, Franky. I believe I followed the instructions on that page. Putting the query into a file works as described. Typing into the powershell does not. Might be a specific Windows issue.

Here is the result in debug mode:

Input:
.\influx.exe query ‘from(bucket:“ExBucket”) |> range(start:-1y)’ --http-debug

Output:
2022/01/01 19:19:14
POST /api/v2/query?org=ExOrganization HTTP/1.1
Host: localhost:8086
User-Agent: influx/2.2.0 (windows) Sha/c3690d8 Date/2021-10-21T15:24:59Z
Transfer-Encoding: chunked
Accept: application/json
Accept-Encoding: gzip
Authorization: Token XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Content-Type: application/json

9f
{“dialect”:{“annotations”:[“group”,“datatype”,“default”],“delimiter”:",",“header”:true},“query”:“from(bucket:ExBucket)|\u003erange(start:-1y)”,“type”:“flux”}

0

2022/01/01 19:19:14
HTTP/1.1 400 Bad Request
Transfer-Encoding: chunked
Content-Type: application/json; charset=utf-8
Date: Sat, 01 Jan 2022 18:19:14 GMT
Vary: Accept-Encoding
X-Influxdb-Build: OSS
X-Influxdb-Version: 2.1.1
X-Platform-Error-Code: invalid

4f
{“code”:“invalid”,“message”:“error @1:13-1:21: undefined identifier ExBucket”}
0

Error: failed to execute query: 400 Bad Request: error @1:13-1:21: undefined identifier ExBucket

You need to escape double quotes by \:
.\influx.exe query 'from(bucket:\"ExBucket\") |> range(start:-1y)' --http-debug

Thanks - unfortunately I find no way to escape the double quotes. " does not work with the Windows PowerShell, since the backslash indicates folders such as the slash in Unix. MS suggests to escape double quotes with “” or `". Both versions won’t work either. Seems to be a very tough one. Probably only few people try with Windows.

The example I have shown works in PowerShell on Windows 10 Pro. Single quotes, ', indicates string and you can use backslash here.

PS C:\influxData\influxdb2-2.1.0-windows-amd64> .\influx.exe query  'from(bucket: \"my-bucket\") |> range(start:-1h) |> filter(fn: (r) => r._measurement == \"stat\" and r._field == \"avg\")' --org my-org -t my-token --http-debug
2022/01/05 17:30:34
POST /api/v2/query?org=my-org HTTP/1.1
Host: localhost:8086
User-Agent: influx/2.2.1 (windows) Sha/31ac783 Date/2021-11-09T21:24:22Z
Transfer-Encoding: chunked
Accept: application/json
Accept-Encoding: gzip
Authorization: Token my-token
Content-Type: application/json

f9
{"dialect":{"annotations":["group","datatype","default"],"delimiter":",","header":true},"query":"from(bucket: \"my-bucket\") |\u003e range(start:-1h) |\u003e filter(fn: (r) =\u003e r._measurement == \"stat\" and r._field == \"avg\")","type":"flux"}

0


2022/01/05 17:30:34
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Content-Type: text/csv; charset=utf-8
Date: Wed, 05 Jan 2022 16:30:34 GMT
Vary: Accept-Encoding
X-Influxdb-Build: OSS
X-Influxdb-Version: 2.1.1

2


0

Ok, thanks. Then I should try to update the powershell.

Mine is: PSVersion 5.1.19041.1320

1 Like