jamesryanbell / cloudflare

CloudFlare API - PHP
https://jamesryanbell.github.io/cloudflare/
206 stars 82 forks source link

Zone AccessRules return 404 due to duplicated // #89

Open redemption opened 5 years ago

redemption commented 5 years ago

I know you're not maintaining this since the official Cloudflare API is available now, but we still use your project so I thought I'd report this.

Recently we're starting to see 404 errors from the Zone\Firewall]\AccessRules class.

The returned output looks like this:

{ "code": 1000, "error": "not_found" }

It turns out the problem has to do with the request URL. All request URLs have a double // in them, which doesn't affect any of the API queries except for the zones one it seems.

Eg this works fine:

GET https://api.cloudflare.com/client/v4//user/firewall/access_rules/rules

But this will be a 404:

GET https://api.cloudflare.com/client/v4//zones/:zoneid/firewall/access_rules/rules

The reason why there are doubled // in the URL path is that all the requests look like this in the code:

return $this->get('/zones/'.$zone_id.'/firewall/access_rules/rules', $data);

But in the get request function it does this:

$url = 'https://api.cloudflare.com/client/v4/'.$path;

The fix is to to remove the extra / in the call to get, eg:

return $this->get('zones/'.$zone_id.'/firewall/access_rules/rules', $data);

Or more universally it's possible to remove the trailing / in the request function.

fmp777 commented 5 years ago

(sorry just side note - i hope this stays maintained! not every server has luxury of going php7 as of yet - which is requirement on the official sdk)