How-To: Executing Queries from Powershell and Bash

Last Updated: 2022-02-25

When using curl from the command line to execute queries you should be aware of the requirement to escape quotes within the queries.

For example, within bash or zsh you can use:

curl -X POST \
 -H 'Authorization: Bearer $TOKEN' \
 -H 'Content-Type: application/json' \
 -H 'Accept: application/x-ndjson' \
 "https://$YOUR_HUMIO_URL/api/v1/repositories/$REPOSITORY_NAME/query" \
 -d '{"queryString": "", "start": "10s", "isLive": true}'

Within Powershell, the quotes must be explicitly escaped:

powershell
curl.exe -X POST \
 -H 'Authorization: Bearer $TOKEN' \
 -H 'Content-Type: application/json' \
 -H 'Accept: application/x-ndjson' \
 "https://$YOUR_HUMIO_URL/api/v1/repositories/$REPOSITORY_NAME/query" \
 -d '{\"queryString\": \"\", \"start\": \"10s\", \"isLive\": true}'

The quotes must be escaped so that they are passed on correctly with the payload.