How to query for special characters with CURL

In influxdb I can query for special characters with:
select * from "%" WHERE entity_id = 'air_quality_balcony' ORDER BY time DESC LIMIT 1;

But for curl this seems not working:

curl -k -G -u 'user:pwd 'https://url/query?pretty=true' --data-urlencode "db=home_assistant" --data-urlencode "q=select * from "%" WHERE entity_id = 'air_quality_balcony' ORDER BY time DESC LIMIT 1"
{
    "error": "error parsing query: found %, expected identifier at line 1, char 15"
}

How can this be achieved?

Thanks for your help!

Do you need to escape the special character?

I think the escape key is \ so possibly something like

curl -k -G -u 'user:pwd ‘https://url/query?pretty=true’ --data-urlencode “db=home_assistant” --data-urlencode “q=select * from “\%\” WHERE entity_id = ‘air_quality_balcony’ ORDER BY time DESC LIMIT 1”

Why do you have a measurement called “%”?

1 Like

You’re an ace, @philb :wink:

Unfortunately this seems also not working.

Does it have something to do with using two sets of double quotes in the curl statement?

Damn, i thought that might fix it :frowning:

@mschae16 would it be a case of escape the inner double quotes as well or just remove the double quotes?

curl -k -G -u 'http://localhost:8086/query?pretty=true' --data-urlencode "db=home_assistant" --data-urlencode "q=select * from \"%\" WHERE \"entity_id\" = 'air_quality_balcony' ORDER BY time DESC LIMIT 1"

Does that work?

2 Likes

That’s the solution. Many thanks!