2016-09-23 42 views
6

我可以利用這個得到了Trello API數據: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次都是荒謬的,但我找不到任何收集所有需要的示例的例子。

回答

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

嘗試擊中以下參數的API:

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

+0

我會檢查一旦我回到我的個人筆記本電腦回家。這是在任何地方的文檔? –