429 - {"status":"error","message":"Api max rps reached"} 发送请求到 manychat sendFlow API

429 - {"status":"error","message":"Api max rps reached"} while sending request to manychat sendFlow API

我正在尝试使用其 API 将 CustomField 设置为 Manychat 订阅者。他们的 API 的 link 是:

https://api.manychat.com/swagger#/Subscriber/post_fb_subscriber_setCustomFieldByName

下面是请求代码:

   var rp = require("request-promise");
   var config = require("./../campaign_config.json");

module.exports = { setWaybillForUser :  async function setWaybillForUser(userid,waybill,dbRef){

        var options = { method: 'POST',
          uri: 'https://api.manychat.com/fb/subscriber/setCustomFieldByName',
          headers: 
           {'Cache-Control': 'no-cache',
             Accept: '*/*',
             Authorization: config.Manychat_token,  
             'Content-Type': 'application/json' },
          body: 
           { subscriber_id: parseInt(userid),
             field_name: 'waybill',
             field_value: waybill },
          json: true };

        try {
        const response = await rp(options);
        console.log(response);
        if (response.status == "success") {
            return dbRef.child('datanode').child(userid).update({
                "Order_Status": 3
            }).then(function () {
                //do nothing.
            }).catch(function (error) {
                console.log(error);
            });
        }
    }
    catch (err) {
        console.log(err.message);
    }
    }
};

我多次调用此函数,因为该函数必须针对许多订阅者 运行。调用它的代码是:

dbRef.child("subData").once('value').then(function(snapshot){
        var data = snapshot.val();
        var keys = Object.keys(data);

        let promiseArray = [];
        let orderStatusArr =[];
        for(let i=0; i< keys.length; i++){

                    var order_status =  data[keys[i]].Order_Status;
                    var subid =  data[keys[i]].UserID;
                    var waybill =  data[keys[i]].Waybill_Number;
                    if(order_status == 1){
                        orderStatusArr.push({
                            "Order_Status":order_status,
                            "UserID": subid,
                            "Waybill_Number":waybill
                        });
                    }
        }

        for(let i=0; i<orderStatusArr.length;i++){
            var order_status =  orderStatusArr[i].Order_Status;
            var subid =  orderStatusArr[i].UserID;
            var waybill =  orderStatusArr[i].Waybill_Number;

            promiseArray.push(setWaybillsForUser.setWaybillForUser(subid,waybill,dbRef));
        }

        Promise.all(promiseArray).then(() => {
            // all done here
            response.send("success");
        }).catch(function(err) {
            console.log(err.message); 
          });

    })

当我 运行 代码时 - 它会记录某些请求的成功,同时为其他请求抛出上述内容。一次它可以 运行 成功地为大约 10 个订阅者发送代码。

来自this page

Is there any limit to a number of API calls?

There is only a request per second limit for POST methods (per page):

  1. /fb/sending/sendFlow, /fb/sending/sendContent - 25 RPS;
  2. /fb/subscriber/addTag, /fb/subscriber/removeTag, /fb/subscriber/setCustomField - 10 RPS.

因此,从这个以及您发布的症状来看,第二条规则似乎适用