Create Rate Limit API not working

I’m trying to set up Rate limiting through API and Passing same data as in example but getting this error “ratelimit.api.unknown_error”. There is no information in response for this error.
Here is a response

{
    "result": null,
    "success": false,
    "errors": [
        {
            "message": "ratelimit.api.unknown_error"
        }
    ],
    "messages": []
}

Which plan do you have?

Is rate-limiting enabled from your Cloudflare Dashboard? Could you send us an example of your API request so we can verify all looks ok? Just make sure to redact your API tokens and any other PII.

https://api.cloudflare.com/#rate-limits-for-a-zone-create-rate-limit

What do you mean by rate-limiting enabled from your Cloudflare Dashboard? Can you please elaborate?
Here is my API request written in PHP

        $apiUrl = "https://api.cloudflare.com/client/v4/zones/" . $zoneId . "/rate_limits";
        
        $headers = [
            "X-Auth-Key:" . $this->cloudflareAuthKey,
            "X-Auth-Email:" . $this->cloudflareEmail,
            "Content-Type: application/json",
            "Accept: application/json"
        ];
        $action = new \stdClass;
        $action->mode = "ban";
        $action->timeout = "86400";

        $match = new \stdClass;
        $match->request = new \stdClass;
        $match->request->url = "*/wlwmanifest*";
         
        $data = [
        "match" => $match,
        "threshold" => 10,
        "period" => 2,
        "action" => $action,
    ];
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $apiUrl);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $httpResponse = curl_exec($ch);

        return json_decode($httpResponse);

Free plan

U can’t create API rate limit with the free plan

Where it is mentioned? Cloudflare documentation says that you can add 1 Rate limit rule with block action in free plan.

Oh sorry, I must have read it wrong

Rate-limit is an add-on and is not enabled by default unless you manually subscribe to the service.

Yes, I have already enabled from dashboard.

Ok, can you try the API call with cURL or Postman to see if you can accomplish this without errors that way? It may help rule out any additional issues that may be in place.

https://api.cloudflare.com/#rate-limits-for-a-zone-create-rate-limit

Thanks. I have just tried to call API with Postman and got some minor errors and then it worked well. After that, I have added the same data in code and call API and it is working.

Excellent, glad to know it worked out!

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