Avoid Error 429 in rails 5 with shopify_api gem

Highlighted
Shopify Partner
1 0 0

Hello,

My private app is working like a charm except when i batch a lot of updates, i raise a few times the nasty Error 429 due to api call limit.

How can i check the api credit left using the shopify_api gem ? I see no trace of HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT in my headers oO

Regards,

Vincent

0 Likes
Highlighted
Shopify Expert
76 0 10

Vincent, I think it's possible private apps don't get the rate limit headers. If your app code is executed in a single thread/process, it may be relatively simple to just code a "defensive" approach where you set a counter to 40 and record the start time, and then every time you're about to fire an API request:
1) subtract 1 from counter for the request

2) if counter is at 0, calculate time elapsed since start in seconds N, add N*2 to the counter (never exceeding 40). reset timer to now

3) if you're still at 0, sleep for 1 second and go back to 2.

Pogodan | https://experts.shopify.com/pogodan-dev
0 Likes
Highlighted
New Member
3 0 0

 Hi, @Vincent_REHM2 you can use one of these gems to avoid 429 error.

shopify-api-limits

shopify-api-throttle

 

Hope this helps you!

 

 

0 Likes