Trello API:在一次调用中获取成员、附件和卡片信息


Trello API: get members, attachments, and card information in one call?

我可以使用以下方式从Trello API获取数据:

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());
}

然而,这被分成三个调用。是否有一种方法可以在一次调用中获取卡信息、成员信息和附件信息?文档提到使用&fields=name,id,但这似乎只是限制了从对cards端点的基本调用返回的内容。

每次我需要卡片信息时都要点击API 3次,这是荒谬的,但我找不到任何收集所有需要的示例。

尝试使用以下参数访问API:

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

Trello回复了我,并表示他们会像Vladimir那样回复我。然而,我得到的唯一回应是最初的卡片数据,没有附件和成员。然而,他们也引导我去看这篇关于批处理请求的博客文章。显然,他们从文档中删除了它,因为它造成了混乱。

为了总结这些更改,您实际上调用/batch,并附加urls GET参数,其中包含要访问的端点的逗号分隔列表。最终的工作版本看起来是这样的:

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);
}