Hi,
Has anyone used the API to access log info in a meaningful way?
Below is our initial attempt to collect the logs and also the Shiny usage info with a user appended. It would be helpful to have the app names available too. I think the logs have the app id and the shiny stuff has the content_guid. Any chance of getting decodes for both added to the API in future releases?
if(!success) {install.packages("pacman")
require(pacman)
}
pacman::p_load(jsonlite, httr, curl, dplyr, data.table)
connectServer <- ""
apiKey <- ""
# set up environment
# Note that the connectServer string must have a trailing slash
# get audit logs
authHeader <- add_headers(Authorization = paste("Key", apiKey))
resp <- GET(
paste0(connectServer, "__api__/v1/audit_logs?ascOrder=true&limit=500"),
authHeader
)
payload <- content(resp)
# print first 25!
# print(payload$result)
# now step through the remaining audit logs
log <- rbindlist(payload$result)
while(!is.null(payload$paging[["next"]])) {
resp <- GET(payload$paging[["next"]], authHeader)
payload <- content(resp)
# print the next 25
# print(payload$result)
log <- rbind(log, rbindlist(payload$result))
}
# Get Shiny App Usage
authHeader <- add_headers(Authorization = paste("Key", apiKey))
resp <- GET("localhost:3939/__api__/v1/instrumentation/shiny/usage?ascOrder=true&limit=500",
authHeader)
payload <- content(resp)
shiny_usage <- rbindlist(payload$result)
while(!is.null(payload$paging[["next"]])) {
resp <- GET(payload$paging[["next"]], authHeader)
payload <- content(resp)
# print the next 25
# print(payload$result)
shiny_usage <- rbind(shiny_usage, rbindlist(payload$result))
}
# Get Users
users <- GET("localhost:3939/__api__/v1/users?page_size=500",
add_headers(Authorization = paste("Key", apiKey)))
user_info <- fromJSON(content(users, "text"))
user_info <- data.frame(user_info$results)
user_info
# Join Shiny Usage and Users
shiny_usage <- left_join(shiny_usage, user_info[c("username","guid")], by = c("user_guid"="guid"))