Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Request is throttled #99

Open
MantasR opened this issue Nov 17, 2017 · 3 comments
Open

Error: Request is throttled #99

MantasR opened this issue Nov 17, 2017 · 3 comments

Comments

@MantasR
Copy link

MantasR commented Nov 17, 2017

It doesn't happen all the time, however since I have imports of orders on cron job (every 3 minutes) I sometimes find my server crashed with this error:

{ Error: Request is throttled
    at Promise.try (/home/api/e-shop-sync/node_modules/mws-api/lib/client.js:144:33)
    at tryCatcher (/home/api/e-shop-sync/node_modules/bluebird/js/release/util.js:16:23)
    at Function.Promise.attempt.Promise.try (/home/api/e-shop-sync/node_modules/bluebird/js/release/method.js:39:29)
    at request.then (/home/api/e-shop-sync/node_modules/mws-api/lib/client.js:140:31)
    at tryCatcher (/home/api/e-shop-sync/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/api/e-shop-sync/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/home/api/e-shop-sync/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/home/api/e-shop-sync/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/home/api/e-shop-sync/node_modules/bluebird/js/release/promise.js:693:18)
    at Promise._fulfill (/home/api/e-shop-sync/node_modules/bluebird/js/release/promise.js:638:18)
    at Request._callback (/home/api/e-shop-sync/node_modules/bluebird/js/release/nodeback.js:42:21)
    at Request.self.callback (/home/api/e-shop-sync/node_modules/request/request.js:188:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:194:7)
    at Request.<anonymous> (/home/api/e-shop-sync/node_modules/request/request.js:1171:10)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:191:7)
    at IncomingMessage.<anonymous> (/home/api/e-shop-sync/node_modules/request/request.js:1091:12)
    at Object.onceWrapper (events.js:293:19)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:188:7)
    at endReadableNT (_stream_readable.js:975:12) code: 'RequestThrottled', type: {}
}

Here is my setup:

    if (!marketplaceCredentials.other.meta) {

        marketplaceCredentials.other.meta = {
            retry: true, // retry requests when throttled
            next: true, // auto-paginate
            limit: Infinity // only get this number of items (NOT the same as MaxRequestsPerPage)
        }

    }

    this.mws = new MWSClient(marketplaceCredentials.other);

And here is where I am getting orders:

    if (!query) {
        return Promise.reject("Query not provided");
    }

    if (!query.fromDate) {
        return Promise.reject("From date not provided");
    }

    return new Promise((resolve, reject) => {

        this.mws.Orders.ListOrders({
            MarketplaceId: this.credentials.other.marketplaceId,
            LastUpdatedAfter: new Date(query.fromDate),
        }).then(({result, metadata}) => {

            let that = this;

            console.log("getOrders => orders.length", result.length);

            return Promise.map(result, function (orderItem, index) {

                return that.mws.Orders.ListOrderItems({AmazonOrderId: orderItem.AmazonOrderId}).then(res => {
                    console.log("orderItem.AmazonOrderId", orderItem.AmazonOrderId);
                    orderItem.listOrderItems = res.result;
                    return Promise.resolve(orderItem);
                });

            }, {concurrency: 5});

        }).then(function (result) {

            resolve(result);

        }).catch(error => {
            console.log(error);
            reject(error);
        });

    });
@eli8levit
Copy link

The reason is that amazon has maximum request quota of requests you are able to send. More info: amazon doc

@eli8levit
Copy link

I have a problem related to this issue

When amount of orders is more then 600 there is now way to get all orders at once because the request is throttled. maxResultsPerPage value must be less than 100 so in order to get 600 orders it has to be 6 requests to amazon when maximum request quota is 6: Amazon doc
How to solve this problem??

@l290347877
Copy link

I have a problem related to this issue

When amount of orders is more then 600 there is now way to get all orders at once because the request is throttled. maxResultsPerPage value must be less than 100 so in order to get 600 orders it has to be 6 requests to amazon when maximum request quota is 6: Amazon doc
How to solve this problem??

How to solve this problem, "nextToken" is filtered out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants