Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service.

Solved
AnkitVyas
Tourist
7 0 0

Hi,

I have an issue regarding the app limit exceeded.

I have a shopify plus plan. I am requesting just single request per second even that I getting the error response: 

{"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}

PHP Code:

function multiRequest($data, $options = array()) {

// array of curl handles
$curly = array();
// data to be returned
$result = array();

// multi handle
$mh = curl_multi_init();

// loop through $data and create curl handles
// then add them to the multi-handle
foreach ($data as $id => $d) {

$curly[$id] = curl_init();

$url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d;
curl_setopt($curly[$id], CURLOPT_URL, $url);
curl_setopt($curly[$id], CURLOPT_HEADER, 0);
curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1);

// post?
if (is_array($d)) {
if (!empty($d['post'])) {
curl_setopt($curly[$id], CURLOPT_POST, 1);
curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $d['post']);
}
}

// extra options?
if (!empty($options)) {
curl_setopt_array($curly[$id], $options);
}

curl_multi_add_handle($mh, $curly[$id]);
}

// execute the handles
$running = null;
do {

sleep(1);
curl_multi_exec($mh, $running);
} while($running > 0);


// get content and remove handles
foreach($curly as $id => $c) {
$result[$id] = curl_multi_getcontent($c);
curl_multi_remove_handle($mh, $c);
}

// all done
curl_multi_close($mh);

return $result;
}

I am calling this function to get variant details from variant id.

I have tried all possible approaches but didn't succeed.

 

Any help ?

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 237

I believe that PHP method for curl_multi_exec can in turn call multi-threaded type operations or perhaps pseudo threaded operations, correct? That's likely why this is happening. Try putting that sleep(1) method call within the foreach ($data as $id => $d) loop and see if that helps slow things down a bit.

0 Likes
AnkitVyas
Tourist
7 0 0
I have tried both ways but the result is the same.
0 Likes
AnkitVyas
Tourist
7 0 0

I called 26 requests but only 1 response I get.

Array
(
[0] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[1] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[2] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[3] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[4] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[5] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[6] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[7] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[8] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[9] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[10] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[11] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[12] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[13] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[14] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[15] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[16] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[17] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[18] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[19] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[20] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[21] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[22] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[23] => {"variant":{"inventory_item_id":34893723369565}}
[24] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[25] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
[26] => {"errors":"Exceeded 4 calls per second for api client. Reduce request rates to resume uninterrupted service."}
)

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 237

Are there are other custom/private apps using your API credentials against the Shopify shop? Perhaps add a line in your PHP code to show the current timestamp, including seconds. To see what's really happening.

AnkitVyas
Tourist
7 0 0

Yes, There are many api call by using the same private api key and password.

Is it possible that I create new private app and using that creds to call the curl ? is that works ?

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 237

This is an accepted solution.

Yep, you got it. That's exactly what you need to do. Since multiple apps that share the same API credentials and are concurrently running would definitely cause API throttling to come into play.

AnkitVyas
Tourist
7 0 0

Thanks for helping out. It works by using new private creation.

Many many thanks.

0 Likes