Firewall rule is not editible from API

I’ve connected by API, and changing rules name and description without problem, but I can’t change expression. I’ve try everything but I can’t resolve it.

When I’ve run this command, everything works, except expression:

curl -X PUT "https://api.cloudflare.com/client/v4/zones/xxx/firewall/rules" \
     -H "X-Auth-Email: xxx" \
     -H "X-Auth-Key: xxx" \
     -H "Content-Type: application/json" \
     --data '[{"id":"3fa9f3be966149ed8572d4a76d8826b2","action":"block","priority":50,"paused":false,"description":"Allow test","ref":"MIR-31","filter":{"id":"99f96e19a2a74b548245571b68b288d7","expression":"(ip.geoip.asnum eq 99999)","paused":false,"description":"Test Description","ref":"FIL-100"}}]'

How can I resolve this problem?

Heh…I know the feeling. Until someone told me it’s actually the “filter” part that needs editing, which I’d never heard of. Now you have a new rabbit hole to go down:

https://api.cloudflare.com/#filters-properties

Here’s mine:

curl -X PUT \
     -H "X-Auth-Email: [email protected]" \
     -H "X-Auth-Key: AUTH_KEY" \
     -H "Content-Type: application/json" \
     -d '{
    "id": "'"$filter"'",
    "paused": false,
    "description": "RULE_NAME",
    "expression": "(http.user_agent contains \"AhrefsBot\") or (http.user_agent contains \"BLEX\") or (http.user_agent contains \"DotBot\") or (http.user_agent contains \"MJ12\") or (http.user_agent contains \"python\") or (not cf.client.bot and ip.geoip.asnum in {'"$MY_ASN_LIST"'})"
}' "https://api.cloudflare.com/client/v4/zones/$zone/filters/$filter"

Thank you for sharing your experience, it works!!! Thanks!!!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.