Skip to contents

This document explains how to interact with Trello from R with read-only access. For editing/private access, see Authorized access and Editing functions.

Introduction

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.

Getting data

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:

The 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.
card_updates[, 1:5]
#> # A tibble: 1 × 5
#>   id                       idMemberCreator          appCreator type       date  
#>   <chr>                    <chr>                    <lgl>      <chr>      <chr> 
#> 1 600f56052f0cbc6b0308e3f2 541c236b4467f97670e44e04 NA         updateCard 2021-…

Error handling

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.

  • If on.error="stop", the request call will throw an error, printing out the http status code.
  • If 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.3.1 (2023-06-16)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 22.04.3 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.20.so;  LAPACK version 3.10.0
#> 
#> locale:
#>  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
#>  [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
#>  [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
#> [10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   
#> 
#> time zone: UTC
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] trelloR_0.8.0
#> 
#> loaded via a namespace (and not attached):
#>  [1] vctrs_0.6.3       httr_1.4.7        cli_3.6.1         knitr_1.43       
#>  [5] rlang_1.1.1       xfun_0.40         stringi_1.7.12    purrr_1.0.2      
#>  [9] textshaping_0.3.6 jsonlite_1.8.7    glue_1.6.2        rprojroot_2.0.3  
#> [13] htmltools_0.5.6   ragg_1.2.5        sass_0.4.7        fansi_1.0.4      
#> [17] rmarkdown_2.24    tibble_3.2.1      evaluate_0.21     jquerylib_0.1.4  
#> [21] fastmap_1.1.1     yaml_2.3.7        lifecycle_1.0.3   memoise_2.0.1    
#> [25] stringr_1.5.0     compiler_4.3.1    fs_1.6.3          pkgconfig_2.0.3  
#> [29] systemfonts_1.0.4 digest_0.6.33     R6_2.5.1          utf8_1.2.3       
#> [33] pillar_1.9.0      curl_5.0.2        magrittr_2.0.3    bslib_0.5.1      
#> [37] tools_4.3.1       pkgdown_2.0.7     cachem_1.0.8      desc_1.4.2