• 1 Introduction
    • 1.1 Getting Started
      • 1.1.1 Environments and Environment Variables
      • 1.1.2 Sticky Sessions
  • 2 System Information
    • 2.1 R Versions Available to RStudio Connect
  • 3 Pagination
    • 3.1 Keyset (Cursor) Pagination
    • 3.2 Offset Pagination
  • 4 Users
    • 4.1 Create an RStudio Connect User from LDAP or OAuth2
      • 4.1.1 Search for a User
      • 4.1.2 Create an RStudio Connect User Account
  • 5 Groups
    • 5.1 Create an RStudio Connect Group from LDAP
      • 5.1.1 Search for a Group
      • 5.1.2 Create an RStudio Connect Group
  • 6 User Activity
    • 6.1 User Activity: Shiny Applications
    • 6.2 User Activity: Rendered and Static Content
  • 7 Deploying Content
    • 7.1 Workflow
    • 7.2 Creating Content
    • 7.3 Creating a Bundle
    • 7.4 Uploading Bundles
    • 7.5 Deploying a Bundle
    • 7.6 Task Polling
  • 8 Managing Content
    • 8.1 Read a Content Item
    • 8.2 Update a Single Content Item Field
    • 8.3 Update Multiple Content Item Fields
  • 9 Promoting Content
    • 9.1 Scenario
    • 9.2 Before Starting
    • 9.3 Workflow
    • 9.4 Bundle Download (staging)
    • 9.5 Bundle Upload (production)
    • 9.6 Bundle Deploy (production)

RStudio Connect: Server API Cookbook

3 Pagination

3.1 Keyset (Cursor) Pagination

The following snippet pages through the audit logs, which uses keyset pagination, starting from the most recent entries, 25 entries at a time.

  1. Obtain the server URL and API Key from environment variables.
  2. Call the “Get audit logs” endpoint to get the first page. See the API Documentation for more information.
  3. Parse the response using httr::content.
  4. Print the current page.
  5. Repeat steps 1 through 3 until there are no more results. Note also that the paging.next property in the response is the URL of the next page.
# set up environment
library(httr)
# Note that the connectServer string must have a trailing slash
connectServer <- Sys.getenv("CONNECT_SERVER")
apiKey <- Sys.getenv("CONNECT_API_KEY")

# get audit logs
authHeader <- add_headers(Authorization = paste("Key", apiKey))
resp <- GET(
  paste0(connectServer, "__api__/v1/audit_logs?ascOrder=false&limit=25"),
  authHeader
)
payload <- content(resp)
# print first 25!
print(payload$results)
# now step through the remaining audit logs
while(!is.null(payload$paging[["next"]])) {
  resp <- GET(payload$paging[["next"]], authHeader)
  payload <- content(resp)
  # print the next 25
  print(payload$results)
}

3.2 Offset Pagination

The following snippet pages through the user’s list, which uses offset pagination, 25 entries at a time.

  1. Obtain the server URL and API Key from environment variables.
  2. Call the “Get all users” endpoint to get the first page. See the API Documentation for more information.
  3. Parse the response using httr::content.
  4. Print the current page.
  5. Repeat steps 1 through 3 until there is no more “next” page. Note also that the query parameter page_number determines the page to return.
# set up environment
library(httr)
# Note that the connectServer string must have a trailing slash
connectServer <- Sys.getenv("CONNECT_SERVER")
apiKey <- Sys.getenv("CONNECT_API_KEY")

# get user's list
authHeader <- add_headers(Authorization = paste("Key", apiKey))
apiPrefix <- "__api__/v1/users?page_size=25"
resp <- GET(
  paste0(connectServer, apiPrefix),
  authHeader
)
# get the first page
payload <- content(resp)
# and step through the pages, printing out the results (if any)
while(length(payload$result) > 0) {
  # print the result
  print(payload$results)
  # get the next page
  nextPage <- payload$current_page + 1
  resp <- GET(
    paste0(connectServer, apiPrefix, "&page_number=", nextPage),
    authHeader
  )
  payload <- content(resp)
}