Antonella's avatar

API Trello: Exceeded rate limit to /1/member

I download the member from trello but after 30 requests I get this message:

API downloadMember! object(stdClass)#6648 (2) { ["message"]=> string(32) "Exceeded rate limit to /1/member" ["error"]=> string(19) "RATE_LIMIT_EXCEEDED" }

this is the codewhich unloads the api:

public function get_member($member_by_api) {
        if (count($member_by_api)>0 && is_array($member_by_api))
        {
                Log::debug("Updating member");
                $res = $this->trelloMemberApiService->_downloadMemberFromCard($member_by_api[0]);
            var_dump($res);//print "RATE_LIMIT_EXCEEDED" after about 30 requests
            if (!is_null($res)) {
                    $member = TrelloMember::where("trello_id", $res->id)->first();
                    if (is_null($member))
                    {
                        $member = new TrelloMember([
                            'trello_id' => $res->id,
                            'name' => $res->fullName,
                        ]);
                        $member->save();

                    }


                }

        }
        else
        {
            $member =
            '';
        }


        return $member;
    }

how can i solve?

0 likes
7 replies
tykus's avatar

That rate limit is imposed by the Trello API; the only solution for you is to either

(i) fetch lists of members rather than individual members (if the API provides that endpoint)

or

(ii) work around that rate limit by handling the exception appropriately and pausing execution through the array while the rate limit prevents further requests

Antonella's avatar

i tried to suspend execution with sleep(60) but it doesn't work, i don't understand what time frame it needs @tykus

tykus's avatar

How big is the array? Also, how/where do you sleep, share your current code?

Antonella's avatar

$cards = $cards_service->get_cards();

            foreach($cards as $index=>$card) {
                if($index >0 && $index % 100 === 0) sleep(60);
                echo $index.' of '.count($cards)."\r\n";
               
                $member_di = resolve('TrelloMemberService');
                

                $member = $member_di->get_member($card->idMembers);
             
            }

after 30 call give me error

tykus's avatar

So the rate limit is 30, not a multiple of 100! Maybe impose that limit before sleeping (maybe less that 60 seconds is okay?)

Antonella's avatar

I also understood if I change the condition to 30 after 5 calls I get "RATE_LIMIT_EXCEEDED" @tykus

tykus's avatar

Additionally, there is a limit on requests to /1/members/ of 100 requests per 900 seconds.

https://developer.atlassian.com/cloud/trello/guides/rest-api/rate-limits/

You are probably running up against rate limits from your earlier attempts - max. 100 requests per 15 minutes is going to take a while to decay! I would suggest to create a Job which batches the member ids, and put them on a Queue in a manner that will not run up against the rate limit.

Please or to participate in this conversation.