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());
}
然而,这被分成三个调用。有没有办法一次调用就可以得到卡片信息、会员信息、附件信息? docs 提到使用 &fields=name,id
,但这似乎只限制了从碱基调用返回到 cards
端点的内容。
每次我需要卡片信息时都必须点击 API 3 次,这很荒谬,但我找不到收集所有所需信息的示例。
尝试使用以下参数点击 API:
/cards/[id]?fields=name,idList&members=true&member_fields=all&& attachments=true&&attachment_fields=all
Trello 回复了我,并表示他们会像 Vladimir 那样回答。然而,我从中得到的唯一回应是初始卡数据,没有附件和成员。但是,他们还指示我 this blog post 涵盖了批处理请求。由于它造成的混乱,他们显然将其从文档中删除了。
为了总结这些变化,您实际上调用了 /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);
}
我可以使用以下方法从 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());
}
然而,这被分成三个调用。有没有办法一次调用就可以得到卡片信息、会员信息、附件信息? docs 提到使用 &fields=name,id
,但这似乎只限制了从碱基调用返回到 cards
端点的内容。
每次我需要卡片信息时都必须点击 API 3 次,这很荒谬,但我找不到收集所有所需信息的示例。
尝试使用以下参数点击 API:
/cards/[id]?fields=name,idList&members=true&member_fields=all&& attachments=true&&attachment_fields=all
Trello 回复了我,并表示他们会像 Vladimir 那样回答。然而,我从中得到的唯一回应是初始卡数据,没有附件和成员。但是,他们还指示我 this blog post 涵盖了批处理请求。由于它造成的混乱,他们显然将其从文档中删除了。
为了总结这些变化,您实际上调用了 /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);
}