Viewing Content Information
Problem
You want to view information associated with a content item. For instance, you might want to find GUID of a content item that you know the title of.
Solution
You can use client.content.find()
to create a data frame of all content you have access to, based on the permissions associated with your API key.
from posit import connect
import polars as pl
= "Data Analysis"
CONTENT_TITLE
= connect.Client()
client
= client.content.find()
res = pl.DataFrame(res) content_df
>>> print(content_df)
3, 46)
shape: (
┌────────────────┬────────────────┬────────────────┬─────────────┬───┬────────────────┬──────────┬───────┬───────────────┐id ┆ owner │
│ guid ┆ name ┆ title ┆ description ┆ … ┆ dashboard_url ┆ app_role ┆ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ str ┆ str ┆ str ┆ ┆ str ┆ str ┆ str ┆ struct[4] │
│
╞════════════════╪════════════════╪════════════════╪═════════════╪═══╪════════════════╪══════════╪═══════╪═══════════════╡0b38412d-3cdf… ┆ quarterly_repo ┆ Quarterly Rep ┆ ┆ … ┆ https://conne… ┆ none ┆ 51694 ┆ {"2bd697db-2… │
│ │ a5ad0dd3-cc39… ┆ data_analysis ┆ Data Analysis ┆ ┆ … ┆ https://conne… ┆ viewer ┆ 42383 ┆ {"c2250bb4-4… │
003e900f-5359… ┆ shiny_dashboa… ┆ Shiny Dashboa… ┆ ┆ … ┆ https://conne… ┆ viewer ┆ 34229 ┆ {"c2250bb4-4… │
│ └────────────────┴────────────────┴────────────────┴─────────────┴───┴────────────────┴──────────┴───────┴───────────────┘
You can then filter on any field in the dashboard to get to the data you’re interested in. For example, you could get the GUID for the “Data Analysis” content item.
>>> content_guid = content_df.filter(pl.col("title") == CONTENT_TITLE).select(["title", "guid"])
>>> print(content_guid)
1, 2)
shape: (
┌───────────────┬─────────────────────────────────┐
│ title ┆ guid │--- ┆ --- │
│ str ┆ str │
│
╞═══════════════╪═════════════════════════════════╡-cc39-4040-80ec-e07e4c… │
│ Data Analysis ┆ a5ad0dd3 └───────────────┴─────────────────────────────────┘
The title
attribute isn’t guaranteed to be unique, so you may see multiple GUIDs returned at this stage.
You can use get_content()
to get a data frame of all content you have access to, based on the permissions associated with your API key.
library(connectapi)
library(dplyr)
= "Data Analysis"
CONTENT_TITLE
<- connect()
client
<- get_content(client) content_df
> content_df
# A tibble: 3 × 47
guid name title description access_type locked locked_message connection_timeout read_timeout init_timeout idle_timeout<chr> <chr> <chr> <chr> <chr> <lgl> <chr> <int> <int> <int> <int>
1 a5ad94bc-38… quar… Quar… "" acl FALSE "" NA NA NA NA
2 a5ad0dd3-cc… data… Data… "" all FALSE "" NA NA NA NA
3 003e900f-53… shin… Shin… "" all FALSE "" NA NA NA NA
# ℹ 36 more variables: max_processes <int>, min_processes <int>, max_conns_per_process <int>, load_factor <dbl>,
# memory_request <lgl>, memory_limit <dbl>, cpu_request <lgl>, cpu_limit <lgl>, amd_gpu_limit <lgl>, nvidia_gpu_limit <lgl>,
# service_account_name <lgl>, default_image_name <lgl>, created_time <dttm>, last_deployed_time <dttm>, bundle_id <chr>,
# app_mode <chr>, content_category <chr>, parameterized <lgl>, cluster_name <chr>, image_name <chr>, r_version <chr>,
# py_version <chr>, quarto_version <chr>, r_environment_management <lgl>, default_r_environment_management <lgl>,
# py_environment_management <lgl>, default_py_environment_management <lgl>, run_as <chr>, run_as_current_user <lgl>, …
You can then filter on any field in the dashboard to get to the data you’re interested in. For example, you could get the GUID for the “Data Analysis” content item.
> content_df |>
+ filter(title == CONTENT_TITLE) %>%
+ select(title, guid)
# A tibble: 1 × 2
title guid <chr> <chr>
1 Data Analysis a5ad0dd3-cc39-4040-80ec-e07e4cf04783
The title
attribute isn’t guaranteed to be unique, so you may see multiple GUIDs returned at this stage.
See also
- For more details about the data returned in this recipe, see Get content details in the API Reference.