ZAIN UL ABIDEEN 152
ZAIN UL ABIDEEN 152

Reputation: 67

PHP CURL library gives error 'Rate limit exceeded' of type 'invalid_access_error'

I'm trying to call an API via PHP CURL library. but everytime when i call this error appears.

Array ( 
    [error] => Array ( 
            [type] => invalid_access_error 
            [message] => Rate limit exceeded 
            ) 
    )
$curl = curl_init();
//$result=$this->cronjob_model->get_new_appoiment();
curl_setopt_array($curl, array(
    CURLOPT_URL => "https://api.dentally.co/v1/appointments/1",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_USERAGENT => "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)",
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_HTTPHEADER => array(
        "Authorization: Bearer 2549fc0ac144797a850a9583e3f685d06b830fd6cc17d8dfe4867fce82adb6bc"
    ),
));


$result = curl_exec($curl);
$someArray=json_decode($result, true);
print_r($someArray);
die();

Upvotes: 1

Views: 515

Answers (1)

RiggsFolly
RiggsFolly

Reputation: 94642

If you look at your rate limit you will see if you have hit a limit

$curl = curl_init();
//$result=$this->cronjob_model->get_new_appoiment();
curl_setopt_array($curl, array(
    CURLOPT_URL => "https://api.dentally.co/rate_limit",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_USERAGENT => "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)",
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_HTTPHEADER => array(
        "Authorization: Bearer 2549fc0ac144797a850a9583e3f685d06b830fd6cc17d8dfe4867fce82adb6bc"
    ),
));


$result = curl_exec($curl);
$someArray=json_decode($result, true);
print_r($someArray);

Array
(
    [resources] => Array
        (
            [core] => Array
                (
                    [limit] => 3600
                    [remaining] => 3422
                    [reset] => 1615456800
                )

            [appointment_availability] => Array
                (
                    [limit] => 200
                    [remaining] => 200
                    [reset] => 1615456800
                )

            [sms] => Array
                (
                    [limit] => 300
                    [remaining] => 300
                    [reset] => 1615507200
                )

        )

)

I guess while testing you have been calling the API often, and had blown a limit, which now appears to have been reset.

Upvotes: 1

Related Questions