4 API Keys

API Keys allow you to programmatically access content on RStudio Connect, as well as the Connect Server API. They are a substitute for logging in to RStudio Connect to access content.

API Keys are not associated with any content, and can be used to access any content that the owning user could access while logged in. The best practice is to create a new API Key for each external tool that needs access to content hosted on RStudio Connect, and to give each Key a name that helps you identify the tool that uses it. When the tool no longer needs access, or if you cannot trust the Key at any time, you can quickly revoke access by deleting the Key.

To access content with an API Key you must provide a HTTP header whose key is Authentication and value is Key THE_API_KEY.

All requests to content must be made to the target URL of the published content. You can find the target URL by clicking the ... menu in the upper-right of the content view and select “Open Solo”.

A screenshot of the menu with Open Solo displayed.

A screenshot of the menu with “Open Solo” displayed.

4.1 Examples

4.1.1 Creating and Deleting an API Key

To create an API key, click on the circular picture in the top-right portion of the screen. The picture may have your username next to it if you are viewing RStudio Connect on a large screen. Click the “API Keys” item in the menu that appears, and you should be taken to the API Keys page.

A screenshot of the user menu with Profile, API Keys, Logout items

A screenshot of the user menu with “Profile, API Keys, Logout” items

A screenshot of the API Keys page showing no API keys created

A screenshot of the API Keys page showing no API keys created

On the API Keys page, click “New API Key”. You will be prompted to name your API key.

A screenshot of a dialog titled Create API Key with the name my_api_key entered

A screenshot of a dialog titled “Create API Key” with the name “my_api_key” entered

After creating an API key, you will be shown the key and given an opportunity to put it in a safe location. Once you close the dialog, you will NOT be shown the API key again. This helps to keep your user account safe.

A screenshot showing a created API key

A screenshot showing a created API key

If you have lost an API key, or if you simply don’t need to use the API key anymore, remove the API key by clicking the trash bin icon on the far right column of the API key list.

A screenshot of the API key list showing my_api_key and a trash bin icon

A screenshot of the API key list showing “my_api_key” and a trash bin icon

When you click the trash bin icon, a dialog will ask you to confirm that you want to delete the API key. Successfully deleting the API key will show a green status message at the top of the screen.

4.1.2 Static Content

Suppose you have published a plot whose target URL is http://example.com/content/24/target.html

You can download the content with an API Key via:

curl -o output.html -H 'Authorization: Key YOUR_API_KEY_HERE' \
    'http://example.com/content/24/target.html'

4.1.3 Plumber

Suppose you have published the following Plumber application whose target URL is http://example.com/content/42

## plumber.R

#* @get /mean
normalMean <- function(samples=10){
  data <- rnorm(samples)
  mean(data)
}

The following calls the function at the /mean endpoint with an API Key:

curl -H 'Authorization: Key YOUR_API_KEY_HERE' \
    'http://example.com/content/24/mean?samples=5'

4.1.4 Connect Server API

Examples for using the Connect Server API can be found in the Connect API Cookbook section: 6.