我可以使用以下方法从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
提及docs,但这似乎只限制从基本调用返回到cards
端点的内容。
每次我需要卡片信息时,必须打3次API是荒谬的,但我找不到任何收集所有需要的例子。
答案 0 :(得分:5)
尝试使用以下参数点击API:
/cards/[id]?fields=name,idList&members=true&member_fields=all&& attachments=true&&attachment_fields=all
答案 1 :(得分:4)
要总结这些更改,您基本上会调用/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);
}