ShopifySharp creating orders error rate limit

650 views Asked by At

I'm trying to add orders to Shopify via API (with ShopifySharp), but after 4 orders are added I always get an error.

System.AggregateException: 'One or more errors occurred. ((429 Too Many Requests) Exceeded order API rate limit, please try again in a minute. Upgrade to a paid account to remove this limit.)'

code:

        public async Task AddOrder(Order order)
        {
            try
            {
                Thread.Sleep(1000);
                await orderService.CreateAsync(order);
            }
            catch (ShopifyRateLimitException e)
            {
                await Task.Delay(10000);
                await orderService.CreateAsync(order);
            }

        }
var taskOrders = AddOrder(order);
taskOrders.Wait();

I know there is a rate that allows 2 requests/second, that's why I have Thread.Sleep(1000) (also tried Task.Delay).

Before this call, no API call is made to Shopify. And it always lets you add 3-4 orders and then error pops up.

But for example, when I'm deleting orders one by one, everything works fine (50 orders in 1 min) with the same implementation, just for deleting.

Also, I tried changing policy to "RetryExecutionPolicy" or "SmartRetryExecutionPolicy" provided by ShopifySharp.

Tried changing delay times, but even after 10-sec error still pop up.

App on shopify has all rights.

1

There are 1 answers

0
Austin Turney On

I'm having the same issue. I found setting the "retryOnlyIfLeakyBucketFull" to false in the "RetryExecutionPolicy" will work, but makes my code slower. My time was waiting for 30 seconds.

var service = new OrderService(myShopifyUrl, shopAccessToken);
service.SetExecutionPolicy(new RetryExecutionPolicy(false));

I am open to a better method if anyone has found one. I emailed the dev and am waiting for a reply.