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).
= "https://trello.com/b/wVWPK9I4/r-client-for-the-trello-api"
board = list(fields = "id,name,idList,labels")
param = get_board_cards(board, query = param, limit = 5)
cards #> 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):
1:3]
cards[, #> # A tibble: 5 x 3
#> id name idList
#> <chr> <chr> <chr>
#> 1 600f54e86a3733550971e… Due date - completed 600f54e86a3733550971…
#> 2 600f54e86a3733550971e… Comments 600f54e86a3733550971…
#> 3 600f54e86a3733550971e… How to install 600f54e86a3733550971…
#> 4 600f54e86a3733550971e… Usage example 600f54e86a3733550971…
#> 5 600f54e86a3733550971e… I found a bug! I want a new feat… 600f54e86a3733550971…
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
:
= function(id, ...) {
get_card_updates get_resource(parent = "card", child = "actions", id = id,
filter = "updateCard", ...)
}= get_card_updates(cards[["id"]][4])
card_updates #> GET: https://api.trello.com/1/card/600f54e86a3733550971ed73/actions?limit=100&filter=updateCard
#> OK (HTTP 200).
#> Fetched 1 results
#>
#> Request complete: 1 results.
1:5]
card_updates[, #> # A tibble: 1 x 5
#> id idMemberCreator type date appCreator
#> <chr> <chr> <chr> <chr> <lgl>
#> 1 600f56052f0cbc6b0… 541c236b4467f97670e4… updateC… 2021-01-25T23:36… NA
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.= get_card_actions(id = "wrong_id", on.error = "message")
error #> 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 x 4
#> failed.url failed.status failed.message failed.headers
#> <chr> <int> <chr> <list>
#> 1 https://api.trello.com/1/card/wr… 400 invalid id <named list [3…
Built with
sessionInfo()
#> R version 4.0.5 (2021-03-31)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: elementary OS 5.1.7 Hera
#>
#> Matrix products: default
#> BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
#>
#> locale:
#> [1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C
#> [3] LC_TIME=cs_CZ.UTF-8 LC_COLLATE=C
#> [5] LC_MONETARY=cs_CZ.UTF-8 LC_MESSAGES=en_GB.UTF-8
#> [7] LC_PAPER=cs_CZ.UTF-8 LC_NAME=C
#> [9] LC_ADDRESS=C LC_TELEPHONE=C
#> [11] LC_MEASUREMENT=cs_CZ.UTF-8 LC_IDENTIFICATION=C
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] trelloR_0.7.1
#>
#> loaded via a namespace (and not attached):
#> [1] rstudioapi_0.13 knitr_1.32 magrittr_2.0.1 R6_2.5.0
#> [5] rlang_0.4.10 fansi_0.4.2 stringr_1.4.0 httr_1.4.2
#> [9] tools_4.0.5 xfun_0.22 utf8_1.2.1 cli_2.4.0
#> [13] jquerylib_0.1.3 htmltools_0.5.1.1 ellipsis_0.3.1 yaml_2.2.1
#> [17] digest_0.6.27 tibble_3.1.1 lifecycle_1.0.0 crayon_1.4.1
#> [21] sass_0.3.1 vctrs_0.3.7 curl_4.3 glue_1.4.2
#> [25] evaluate_0.14 rmarkdown_2.7 stringi_1.5.3 compiler_4.0.5
#> [29] bslib_0.2.4 pillar_1.6.0 jsonlite_1.7.2 pkgconfig_2.0.3