Expression validation
The Cloudflare Filters API supports an endpoint for validating expressions.
Operation | Method + Endpoint | Notes |
---|---|---|
Validate expression via query string (?expression=) | GET /filters/validate-expr |
Allows testing and validating expressions without changing anything |
Validate expression via JSON object | POST /filters/validate-expr |
Allows testing and validating expressions without changing anything |
Examples
Validate expression via query string
---
header: Request
---
curl -X GET \
'https://api.cloudflare.com/client/v4/filters/validate-expr?expression=ip.src==34' \
-H "X-Auth-Email: <EMAIL>" \
-H "X-Auth-Key: <API_KEY>"
---
header: Response
---
{
"result": null,
"success": false,
"errors": [
{
"message": "Filter parsing error:\n`ip.src==34`\n ^^ couldn't parse address in network: invalid IP address syntax\n"
}
],
"messages": null
}
Note the validation error in the response. In this example, the error is due to an invalid IP address format:
Filter parsing error:
`ip.src==34`
^^ couldn't parse address in network: invalid IP address syntax
Validate expression via JSON object
---
header: Request
---
curl -X POST \
"https://api.cloudflare.com/client/v4/filters/validate-expr" \
-H "X-Auth-Email: <EMAIL>" \
-H "X-Auth-Key: <API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"expression": "ip.src in {2400:cb00::/32 2405:8100::/2000 2c0f:f248::/32 2a06:98c0::/29}"
}'
---
header: Response
---
{
"result": null,
"success": false,
"errors": [
{
"message": "Filter parsing error:\n`ip.src in {2400:cb00::/32 2405:8100::/2000 2c0f:f248::/32 2a06:98c0::/29}`\n ^^^^ number too large to fit in target type while parsing with radix 10\n"
}
],
"messages": null
}
Note the validation error in the response. In this example, the value for the subnet mask, /2000
, is not a valid IPv6 CIDR mask:
Filter parsing error:
`ip.src in {2400:cb00::/32 2405:8100::/2000 2c0f:f248::/32 2a06:98c0::/29}`
^^^^ number too large to fit in target type while parsing with radix 10