Groups¶
Create an RStudio Connect Group from LDAP¶
The following snippets search for a group in LDAP and then create an RStudio Connect group for that LDAP group.
There are two steps:
- Search for the group via the
GET /groups/remoteendpoint. A group that does not exist on Connect will lack aguid. Note thetemp_ticketfor the desired group. - Use the
PUT /groupsendpoint with thetemp_ticketto create a corresponding group on RStudio Connect.
Search for a Group¶
library(httr) # The connectServer URL must have a trailing slash. connectServer <- Sys.getenv("CONNECT_SERVER") connectAPIKey <- Sys.getenv("CONNECT_API_KEY") # set the search parameter prefix <- "accounting" # make the query request response <- GET( paste0(connectServer, "__api__/v1/groups/remote"), add_headers(Authorization = paste("Key", connectAPIKey)), query = list(prefix = prefix) ) results <- content(response)$results # print the results of the API call formatGuid <- function(guid) { if (is.null(guid)) { "NULL" } else { guid } } cat(sprintf("NAME\tGUID\n")) for (group in results) { cat(sprintf("%s\t%s\n", group$name, formatGuid(group$guid))) }
The output looks like the following:
NAME GUID accounting1 15f5f51d-08ff-4e5b-beba-4ccf24e248dd accounting2 NULL
In this particular case, there are two groups matching the search for
the prefix accounting. The group accounting1 has a GUID value,
which means that this group already exists in RStudio Connect. The
group accounting2 does not yet have a corresponding group in RStudio
Connect.
Included in the API response for each group is a temp_ticket value
that can be used to create the group in RStudio Connect. In the
example above, the second group, accounting2, does not exist in
RStudio Connect, so you will need the temp_ticket for this group:
tempTicket <- results[[2]]$temp_ticket
You can use this tempTicket value in the next section to create the
group.
Create an RStudio Connect Group¶
Using the tempTicket value from the previous section, you can create
an RStudio Connect group with an HTTP PUT request:
library(httr) # The connectServer URL must have a trailing slash. connectServer <- Sys.getenv("CONNECT_SERVER") connectAPIKey <- Sys.getenv("CONNECT_API_KEY") # The 'tempTicket' value comes from an earlier /groups/remote search. response <- PUT( paste0(connectServer, "__api__/v1/groups"), add_headers(Authorization = paste("Key", connectAPIKey)), body = list(temp_ticket = tempTicket), encode = "json" ) print(content(response))
When the call succeeds, the response will contain a non-NULL guid value,
which is a unique identifier for the group.
If the group already exists in Connect, the response will contain an error:
$error [1] "The requested group name is already in use."