Connect API: Getting all content associated with a specific tag

Hello everybody!

I love Connect and recently stumbled over the API and the super-convenient connectapi package to directly access the API even without the usage of HTTP request packages like httr.

But for one thing I did not find a good solution yet. With connectapi::get_content() I get a tibble with various variables about the content on Connect. But there is no information about the tags associated with every piece of content. If I want to get the tags associated, I have to call connectapi::content_item(client, guid)$tags() (where guid is the guid retrieved by connectapi::get_content()) for every content item, which takes ~10 seconds for the ~50 deployed content items on our company's Connect server. Is there a more direct way to get the content associated with a tag (or getting all content with the tags at once), instead of getting the tags for every content item one-by-one? I've not found anything like this directly in the API reference here.

Thank you very much in advance!

2 Likes

Hey @juma728 ! Very glad to hear the API and the connectapi package have been helpful for you! We do not have an ideal solution to your problem today, although we are looking forward to improving this story!

The "workaround" that should get you what you want, I believe, is something like this:

library(connectapi)
client <- connect()
#> Defining Connect with host: https://colorado.rstudio.com/rsc

all_tags <- get_tags(client)
#> Warning: The `get_tags` function is experimental and subject to change without warning in a future release
#> This warning is displayed once per session.

get_content(client, filter = list(tag = paste(c(all_tags$Technology$BackEnds$id, all_tags$Technology$Email$id), collapse = ":")))
#> Warning: The `get_content` function is experimental and subject to change without warning in a future release
#> This warning is displayed once per session.
#> # A tibble: 5 x 36
#>      id guid  access_type connection_time… read_timeout init_timeout
#>   <int> <chr> <chr>                  <dbl>        <dbl>        <dbl>
#> 1  4045 780e… all                       NA           NA           NA
#> 2  3660 a510… all                       NA           NA           NA
#> 3  2543 158e… acl                       NA           NA           NA
#> 4  1008 d568… logged_in                 NA           NA           NA
#> 5   724 e576… all                       NA           NA           NA
#> # … with 30 more variables: idle_timeout <dbl>, max_processes <int>,
#> #   min_processes <int>, max_conns_per_process <int>, load_factor <dbl>,
#> #   url <chr>, vanity_url <lgl>, name <chr>, title <chr>, bundle_id <int>,
#> #   app_mode <int>, content_category <chr>, has_parameters <lgl>,
#> #   created_time <dttm>, last_deployed_time <dttm>, r_version <chr>,
#> #   py_version <chr>, build_status <int>, run_as <chr>,
#> #   run_as_current_user <lgl>, description <chr>, app_role <chr>,
#> #   owner_first_name <chr>, owner_last_name <chr>, owner_username <chr>,
#> #   owner_guid <chr>, owner_email <chr>, owner_locked <lgl>,
#> #   is_scheduled <lgl>, git <list>

Created on 2020-09-30 by the reprex package (v0.3.0)

As with other experimental parts of the connectapi package, it is good to (1) pin the version of the connectapi you are using with renv or some such, (2) be wary that upgrading Connect could change API endpoints without warning and cause issues.

We are hoping to stabilize some of these experimental parts of the API in coming releases, and when we do so, we expect that some of this will become a bit nicer in the package as well. For now, this should work though! :smile:

Please let us know if you run into any trouble, or if you have feedback on the API, package, etc. We love hearing what the API enables for our customers!

1 Like

Hi cole!

Great, thank you very much for providing the workaround, I've tested it and it works!

I will definitely look into how to how to use renv to keep the configuration working and will check the app I'm developing after any Connect upgrade. At the moment I'm still using the API and the package only in a relatively unimportant app, so it wouldn't be too bad if it didn't work for a while. Thanks for all the information!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.