Error 10014 (filters.api.malformed_request_body) when trying to add Continent Filter

I am able to use the code below to add filters until I change it to add the country/continent list with the quotations. I have also tried " in the list. I have list of 900+ sites that I want to add the same standard filter/firewall rule

Does anyone know how to format the expression to work?

curl -X POST
https://api.cloudflare.com/client/v4/zones/ZONEID/filters
-H “X-Auth-Email: EMAIL”
-H “Authorization: Bearer ZZZZZZZZZZZZZZZZZZZ”
-H “Content-Type: application/json”
-d ‘[
{
“expression”: “(not ip.geoip.country in {“CN”})”
}]’

There is a filter expression validator you can use:

https://developers.cloudflare.com/firewall/api/cf-filters/validation/

In your case I see two issues. You need to escape the " as in the example below. You are also mixing API Token auth and API Key auth.

% curl -X POST \
"https://api.cloudflare.com/client/v4/filters/validate-expr" \
-H "X-Auth-Email: $auth_email" \
-H "X-Auth-Key: $auth_key" \
-H "Content-Type: application/json" \
-d '{
  "expression": "not ip.geoip.country in {\"CN\"}"
}'

{
  "result": null,
  "success": true,
  "errors": null,
  "messages": null
}
1 Like

I did try the " and it still fails. I am able to put in following example with the authorization method
‘[
{
“expression”: “ip.src eq 93.184.216.0”
}’