Filtering cards through customFields via Rest API

Hi there,

I need to query Trello in order to fetch some cards based on customFields. I’ve studying Trello Rest API and based on my findings, I would need to:

1 - List all cards for a given Board:

  • {{trelloAPIURL}}/boards/${id}/cards/?lists=all&list_fields=all&key={{trelloKey}}&token={{trelloToken}}

2 - “For each” card, I would need to query all custom Fields:

  • {{trelloAPIURL}}/cards/${id}/?fields=all&customFieldItems=true&board_fields=true&key={{trelloKey}}&token={{trelloToken}}

3 - and finally for each custom Field, I would need to get it’s options:

  • {{trelloAPIURL}}/customFields/${card_id}/options/${id}/?key={{trelloKey}}&token={{trelloToken}}

With that said:

1 - Is there any better option ? Any method that I’m missing ?
2 - Is there any sort of API/Method/Resource that fetches all cards alongside it’s customFields ?

  • something that would reduce the amount of round-trips/hits on Trello;

Thanks in advance.

Best regards,

You can fetch all cards with customFields(customFieldItems query parameter):
{{trelloAPIURL}}/boards/${id}/cards/?lists=all&customFieldItems=true,list_fields=all&key={{trelloKey}}&token={{trelloToken}}
And then just get custom fields for the board(options will be there) and you will have everything about custom fieds in cards.

1 Like

Hi there,

Thank you very much for your help. In deed solved my problem, although I’ll have to query customFields endpoint in order to fetch it’s labels.

"customFieldItems": [
            {
                "id": "5e7bfb897d6400573055fcdb",
                "idValue": "5e79169f0ca22e7369ad9711",
                "idCustomField": "5e79169f0ca22e7369ad9710",
                "idModel": "5e7ba4c3efbf8276b0ed1f94",
                "modelType": "card"
            },
            {
                "id": "5e7bfb875abea60ecde57145",
                "idValue": "5e7915237f4bfc36c67af444",
                "idCustomField": "5e7914fc7285d4227b2794f4",
                "idModel": "5e7ba4c3efbf8276b0ed1f94",
                "modelType": "card"
            }
        ]

Furthermore your suggestion had a typo on it. The correct URI is the following:

{{trelloAPIURL}}/boards/${board_id}/cards/?lists=all&customFieldItems=true&list_fields=all&key={{trelloKey}}&token={{trelloToken}}

Thanks once more! really appreciate your help/time!

Bets regards,
Vinicius Branda Martinez

But you can fetch customFields of the board to get labels for every custom field in the card. So it’s only one request per board, not one request per card.