Skip to contents

Make a request to the Canvas LMS API and automatically handle pagination. The results from all pages are aggregated. If tibblify is FALSE, returns a list where each element is a list representing a "page" of results. If tibblify is TRUE (default), the pages are concatenated and compacted (i.e. dropping NULL elements) and turned into a tibble with tidyr::unnest_wider().

Usage

canvas_paginate(req, tibblify = TRUE, per_page = 500, ...)

Arguments

req

A httr2 request object prepared for the Canvas LMS API.

tibblify

Whether to return the result as a tibble or as a list (default TRUE).

per_page

Number of elements in each page (default 10, upper limit undocumented).

...

Additional arguments passed to httr2::req_perform.

Value

If tibblify is TRUE, returns a tibble aggregating all the results from the paginated responses. If tibblify is FALSE, returns a list of results from all pages.

Examples

canvas_api("users") |> canvas_paginate()
#> # A tibble: 5 × 8
#>      id name      created_at sortable_name short_name sis_user_id login_id email
#>   <int> <chr>     <chr>      <chr>         <chr>      <chr>       <chr>    <chr>
#> 1 24648 Kathrine… 2018-12-2… Frøslie, Kat… Kathrine … fs:192:813… kathrfr… kath…
#> 2 37821 Berit Ka… 2021-07-2… Økland, Beri… Berit Kar… fs:192:929… beriokl… beri…
#> 3  2421 Lars-Gus… 2017-02-2… Snipen, Lars… Lars-Gust… fs:192:5214 larssn@… lars…
#> 4  4274 Ronny St… 2017-02-2… Steen, Ronny  Ronny Ste… fs:192:1573 roste@n… ronn…
#> 5  4518 Jon Olav… 2017-02-2… Vik, Jon Olav Jon Olav … fs:192:4921 jonvi@n… jon.…
## A tibble with columns id, name, created_at, etc.