Using The Posit Connect API to Gather Application Information

Follow

Since Connect 1.9.0, the URL string for applications hosted on Posit Connect changed from displaying the Application ID to the GUID. Some administrators have reported the need to retain the ability to locate apps by their internal ID. Administrators can use the Connect Content API to view and manage content for applications hosted on Connect, including the GUID and Application IDs. This document serves as a guide for systems administrators who are hoping to find specific application information using the Connect API.

Note: The Posit Connect API requires an appropriate license, please contact your Customer Success Rep if you are unsure if this is available.

Generate the API Key

API keys can be found in the Connect dashboard and are organized according to usernames.

Note: to use the Connect Content API, the API key will need to be generated from a user with the Admin role. 

Login to the RStudio Connect dashboard and navigate to People —> Users —> <Your Username>. Underneath the user profile click on “API Keys” and then “New API Key”. Finally, give the API Key a name, enter user credentials and save your API key somewhere safe.

Create an .Renviron File

From the Workbench or Desktop IDE instance, open the terminal and execute the below steps.

Please note: In Posit Workbench you will need to have permission to edit the .Renviron file.

In the home folder of the user that will run the API code, execute the below:

$ sudo touch .Renviron
$ sudo vim .Renviron

# ~/.Renviron
#The CONNECT_SERVER URL must have a trailing slash.
CONNECT_SERVER="<full_url_to_connect_with_trailing_slash>"
CONNECT_API_KEY="<your_api_key>"

After this is completed, save the file and then restart the R Session in the IDE. This can be done by going to Session —> Restart R

Create the Script

In the IDE, create an R script file (File —>  New File —>  R Script) with the below contents and run the entire block. 

---
title: "Get Content List"
output: html_notebook
---

```{r}
connectServer <- Sys.getenv("CONNECT_SERVER")
apiKey <- Sys.getenv("CONNECT_API_KEY")

library(httr)

result <- GET(paste0(connectServer, '__api__/v1/content'),
add_headers(Authorization = paste("Key", apiKey)))

content(result)
```

The output will then be displayed like the below:

[[1]]
[[1]]$guid
[1] "ce8d2232-2a96-4146-9c02-da5564a1d7c2"

[[1]]$name
[1] "GesyerRedo-1656009359933"

[[1]]$title
[1] "GesyerRedo"

[[1]]$description
[1] ""

[[1]]$access_type
[1] "acl"

[[1]]$connection_timeout
NULL

[[1]]$read_timeout
NULL

[[1]]$init_timeout
NULL

[[1]]$idle_timeout
NULL

[[1]]$max_processes
NULL

[[1]]$min_processes
NULL

[[1]]$max_conns_per_process
NULL

[[1]]$load_factor
NULL

[[1]]$created_time
[1] "2022-06-23T18:36:00Z"

[[1]]$last_deployed_time
[1] "2022-06-23T18:46:27Z"

[[1]]$bundle_id
[1] "7"

[[1]]$app_mode
[1] "shiny"

[[1]]$content_category
[1] ""

[[1]]$parameterized
[1] FALSE

[[1]]$cluster_name
[1] "Local"

[[1]]$image_name
NULL

[[1]]$r_version
[1] "3.6.3"

[[1]]$py_version
NULL

[[1]]$quarto_version
NULL

[[1]]$run_as
NULL

[[1]]$run_as_current_user
[1] FALSE

[[1]]$owner_guid
[1] "57e0cafe-c8f5-469a-a105-592fb5f5f045"

[[1]]$content_url
[1] "<your_url>/content/ce8d2232-2a96-4146-9c02-da5564a1d7c2/"

[[1]]$dashboard_url
[1] "<your_url>/connect/#/apps/ce8d2232-2a96-4146-9c02-da5564a1d7c2"

[[1]]$app_role
[1] "owner"

[[1]]$id
[1] "5"

 

The script output contains both the ID and the GUID for each application. Systems administrators can use the Connect Content API to generate this information, along with other useful data points such as timestamps and specific application process settings. That information can then be used to parse through server data related to Connect applications or given to the Posit Support team if needed. 

Comments