Trello API:在一次通话中获取会员,附件和卡信息?

时间:2016-09-23 21:14:00

标签: php trello

我可以使用以下方法从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是荒谬的,但我找不到任何收集所有需要的例子。

2 个答案:

答案 0 :(得分:5)

尝试使用以下参数点击API:

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

答案 1 :(得分:4)

Trello回答我说,他们会像弗拉基米尔那样回答。但是,我从中得到的唯一回应是初始卡片数据,没有附件和成员。但是,他们还指示我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);
}