This document explains how to interact with Trello from R with read-only access. For editing/private access, see Authorized access and Editing functions.
Most things in Trello live on a Board. A board encapsulates a hierarchy of resources: Members, Teams, Lists, Cards, Custom fields and Actions. Some of the resources may contain additional data (e.g. cards may have labels, due dates etc.) or other nested resources (e.g. boards may have lists, cards, label definitions etc.)
Each resource can have a parent resource (e.g. a board is a parent resource for a card) and child resources (a card can include actions as a child resource). A resource can have more than one parent (a board and a list are both parents to a card).
To access a resource, you need to know its unique ID, or the ID of its parent resource. In some cases (e.g. boards or cards), you can use the resource URL instead.
The following snippet fetches 5 cards from the trelloR demo board. This is a public board and so does not require authentication:
library(trelloR)
#> R API for Trello
#> Disclaimer: trelloR is not affiliated, associated, authorized, endorsed by or
#> in any way officially connected to Trello, Inc. (www.trello.com).
board = "https://trello.com/b/wVWPK9I4/r-client-for-the-trello-api"
param = list(fields = "id,name,idList,labels")
cards = get_board_cards(board, query = param, limit = 5)
#> GET: https://api.trello.com/1/board/wVWPK9I4/cards?fields=id%2Cname%2CidList%2Clabels&limit=5
#> OK (HTTP 200).
#> Fetched 5 results
#>
#> Request complete: 5 results.
The result is a data.frame (or a tibble if installed):
cards[, 1:3]
#> # A tibble: 5 × 3
#> id name idList
#> <chr> <chr> <chr>
#> 1 600f54e86a3733550971ed6b Due date - completed 600f54e86a37335…
#> 2 600f54e86a3733550971ed75 Comments 600f54e86a37335…
#> 3 600f54e86a3733550971ed6f How to install 600f54e86a37335…
#> 4 600f54e86a3733550971ed73 Usage example 600f54e86a37335…
#> 5 600f54e86a3733550971ed71 I found a bug! I want a new feature! 600f54e86a37335…
Nested resources can be obtained by querying their parent resource. In the example above, we didn’t have to query each card individually - instead, we just queried the board resource to get all of its cards.
A general way of retrieving data from a board is to use the function
get_resource()
which allows you to specify parameters of
the query. However, trelloR
also includes a number of
wrappers for specific resources. For example:
get_board_cards()
to get cards from a particular
boardget_card_members()
to get a list of people assigned
to a cardget_board_fields()
to get custom field
definitionsget_card_fields()
to get custom field valuesThe following example creates a wrapper to fetch updates to a given
card. This is represented by the “updateCard” action type passed to
filter
:
get_card_updates = function(id, ...) {
get_resource(parent = "card", child = "actions", id = id,
filter = "updateCard", ...)
}
card_updates = get_card_updates(cards[["id"]][4])
#> GET: https://api.trello.com/1/card/600f54e86a3733550971ed73/actions?limit=100&filter=updateCard
#> OK (HTTP 200).
#> Fetched 1 results
#>
#> Request complete: 1 results.
If a request fails andretry.times > 1
, it will be
re-attempted. If it fails after all attempts are spent, the subsequent
behavior is determined by the on.error
argument.
on.error="stop"
, the request call will throw an
error, printing out the http status code.on.error="warn"
or "message"
, a data
frame is returned, containing the failed request URL, the error message
generated by the API, and response headers.error = get_card_actions(id = "wrong_id", on.error = "message")
#> GET: https://api.trello.com/1/card/wrong_id/actions?limit=100
#> invalid id (HTTP 400)
#>
#> Fetched 1 results
#>
#> Request complete: 1 results.
error
#> # A tibble: 1 × 4
#> failed.url failed.status failed.message failed.headers
#> <chr> <int> <chr> <list>
#> 1 https://api.trello.com/1/card/wro… 400 invalid id <named list>
Built with
sessionInfo()
#> R version 4.4.1 (2024-06-14)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 24.04.1 LTS
#>
#> Matrix products: default
#> BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
#>
#> locale:
#> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
#> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=C
#> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
#> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
#> [9] LC_ADDRESS=C LC_TELEPHONE=C
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
#>
#> time zone: Etc/UTC
#> tzcode source: system (glibc)
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] trelloR_0.8.0 rmarkdown_2.28
#>
#> loaded via a namespace (and not attached):
#> [1] vctrs_0.6.5 httr_1.4.7 cli_3.6.3 knitr_1.48
#> [5] rlang_1.1.4 xfun_0.49 jsonlite_1.8.9 glue_1.8.0
#> [9] buildtools_1.0.0 htmltools_0.5.8.1 maketools_1.3.1 sys_3.4.3
#> [13] sass_0.4.9 fansi_1.0.6 evaluate_1.0.1 jquerylib_0.1.4
#> [17] tibble_3.2.1 fastmap_1.2.0 yaml_2.3.10 lifecycle_1.0.4
#> [21] compiler_4.4.1 pkgconfig_2.0.3 digest_0.6.37 R6_2.5.1
#> [25] utf8_1.2.4 pillar_1.9.0 curl_5.2.3 magrittr_2.0.3
#> [29] bslib_0.8.0 tools_4.4.1 cachem_1.1.0