Firewall Rule PUT API call not working

I’m trying to update a firewall rule through an API call. For now, I’m just using CURL to rest out the API call before moving it into a production script. However, the filter portion of the API call is not working. When I perform the following API PUT call:

curl --request PUT \
    --url https://api.cloudflare.com/client/v4/zones/{zone_identifier}/firewall/rules/{id} \
    --header 'Content-Type: application/json' \
    --header 'X-Auth-Email: myEmail' \
    --header 'X-Auth-Key: myAPIKey' \
    --data '{"id":"firewallRuleID", "paused":false, "description":"Description of my Rule", "action":"allow", "ref":"refIDofMyRule", "filter": {"description":"An informative summary of the filter.", "id": "The unique identifier of the filter.","expression": "(ip.src eq 3.3.3.3)", "paused":false}}'

The ip.src is not updating. Instead, the response returns the IP that is already there. In this example 1.1.1.1.
Response:

{
    "result": {
        "id": "FireWall ID",
        "paused": false,
        "description": "Firewall Rule Description",
        "action": "skip",
        "ref": "refIDofMyRule",
        "filter": {
            "id": "The unique identifier of the filter.",
            "expression": "(ip.src eq 1.1.1.1)",
            "paused": false
        },
        "created_on": "2023-07-28T19:11:55Z",
        "modified_on": "2023-07-28T22:47:56Z",
        "index": 0
    },
    "success": true,
    "errors": [],
    "messages": []
}

Not sure if I’m doing something wrong or if there is a bug with the API.
Any guidance would be appreciated!

Hi,

You’re trying to update the filter within the firewall rule. However, filters have their own endpoint, and you must update them separately.

2 Likes

Building off @cbrandt, but the firewall and filter rules are being deprecated and replaced by the ruleset API

2 Likes

Thank you for taking the time to respond. Once, I changed the endpoint to just filters it worked like a charm. Thank you.

Thank you @Cyb3r-Jak3. I tried @cbrandt before I saw your post. I got it working using filters only endpoint. However, I’m going to update my API code to use ruleset since it’s going to be deprecated and I’m looking to use this as a long term solution with my router.
Thank you for taking the time to provide me with this info!

1 Like