Getting Started with connectapi

Cole Arendt



The first thing that you need to accomplish when using the connectapi is getting connected to your Posit Connect server. This requires the URL to your server and an API key. Directions on how to get an API key are here.

Once you have your API key, you can create a Connect object in your code, like so:

client <- connect(
  server = "",
  api_key = "aihgaahegiahgg"

The alternative is to define a .Renviron file, which specifies environment variables:


Then, those can be used in your code:


# this happens by default if you restart your R session

client <- connect()

Content Management

The connectapi package has tools to help programmatically deploy and manage content. To get started, you need to use the rsconnect package, specifically the rsconnect::writeManifest() function, to build a manifest.json file for a directory of content that you want to deploy.

Once the manifest.json file is present, you can reference the directory and deploy it directly:

bnd <- bundle_dir("./my/directory")

# name must be unique on the server
# if you do not specify it, a random value will be provided
content_1 <- client %>%
  deploy(bnd, name = "my-content", title = "Amazing Report!!")

The content object (content_1) includes information about the deployment that you just requested. This can be explored with:

content_1 %>% poll_task()

Alternatively, you can immediately begin altering the settings of the content object while you wait for deployment to complete:

content_1 %>%
  set_image_url("") %>%

# ensure the vanity URL is set as expected
content_1 %>%

If you have content that already exists and you want to update it, you can do so using the content GUID (which you can find within Posit Connect in the Info pane).

content_2 <- client %>%
  deploy(bnd, guid = "d78ba9f8-bb57-422e-b164-9ecd8e4c4fd6") %>%

You can also use the Posit Connect content GUID to retrieve information about existing content (if you want to examine or change settings)

content_3 <- client %>%
  content_item(guid = "96532fbc-725e-441b-9cc6-a5622535241b")