7

I can get data from the Trello API using this:

private function get_card_info($card_id) {
    $client =         new \GuzzleHttp\Client();
    $base =           $this->endpoint . $card_id;
    $params =         "?key=" . $this->api_key . "&token=" . $this->token;      
    $cardURL =        $base . $params;
    $membersURL =     $base . "/members" . $params;
    $attachmentsURL = $base . "/attachments" . $params;

    $response = $client->get($cardURL);
    $this->card_info['card'] = json_decode($response->getBody()->getContents());

    $response = $client->get($membersURL);
    $this->card_info['members'] = json_decode($response->getBody()->getContents());

    $response = $client->get($attachmentsURL);      
    $this->card_info['attachments'] = json_decode($response->getBody()->getContents());
}

However, this is broken into three calls. Is there a way to get card information, the member information, and the attachment information all in one call? The docs mention using &fields=name,id, but that only seems to limit what's returned from the base call to the cards endpoint.

It's absurd to have to hit the API 3 times every time I need card information, but I can't find any examples gathering all that's needed.

2 Answers 2

7
+25

Try hitting the API with following parameters:

/cards/[id]?fields=name,idList&members=true&member_fields=all&& attachments=true&&attachment_fields=all

1
  • I'll check this as soon as I get home to my personal laptop. Is this in the docs anywhere? Commented Sep 26, 2016 at 14:33
3

Trello replied to me, and stated that they would have answered much like Vladimir did. However, the only response I got from that was the initial card data, sans attachments and members. However, they also directed me to this blog post that covers batching requests. They apparently removed it from the docs because of the confusion it created.

To summarize the changes, you essentially make a call to /batch, and append a urls GET parameter with a comma separated list of endpoints to hit. The working final version ended up looking like this:

private function get_card_info($card_id) {
    $client =         new \GuzzleHttp\Client();
    $params =         "&key=" . $this->api_key . "&token=" . $this->token;

    $cardURL = "/cards/" . $card_id;
    $members = "/cards/" . $card_id . "/members";
    $attachmentsURL = "/cards/" . $card_id . "/attachments";

    $urls = $this->endpoint . implode(',', [$cardURL, $members, $attachmentsURL]) . $params;

    $response = $client->get($urls);
    $this->card = json_decode($response->getBody()->getContents(), true);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.