Viewing Vanity URLs
Problem
You want to view the Vanity URL associated with your Content.
Solution
Requires posit-sdk>=0.6.0
Obtain the content object for your Content. In this example, we get the Content using its GUID.
from posit import connect
client = connect.Client()
CONTENT_GUID = "154bd2af-e8fa-4aa4-aab8-dcef701f4af9"
content = client.content.get(CONTENT_GUID)Then read the content.vanity attribute to view the Vanity URL path.
>>> content.vanity
"/my-dashboard/"If the Content does not have a Vanity URL, the value is None.
>>> print(content.vanity)
NoneUse the Content GUID to look up its Vanity URL.
library(connectapi)
CONTENT_GUID <- "154bd2af-e8fa-4aa4-aab8-dcef701f4af9"
client <- connect()
content <- content_item(client, CONTENT_GUID)
vanity <- get_vanity_url(content)The get_vanity_url() function returns a character vector containing the Vanity URL.
> vanity
[1] "/my-dashboard/"If the Content does not have a Vanity URL, the value is NULL.
> vanity
NULLViewing when a Vanity URL was created
The Connect server stores the timestamp for when the Vanity URL was created.
The content.vanity attribute returns only the Vanity URL path. To view the entire vanity object, including the creation timestamp, call the content.find_vanity method.
>>> content.find_vanity()
{ "path": "/my-dashboard/", "content_guid": "154bd2af-e8fa-4aa4-aab8-dcef701f4af9", "created_time": "2024-08-01T20:44:58Z" }The get_vanity_url() function returns only the Vanity URL path. To view the creation timestamp, call get_vanity_urls() and filter the result by the Content GUID.
The get_vanity_urls() function requires administrator privileges.
vanities <- get_vanity_urls(client)
vanities[vanities$content_guid == CONTENT_GUID, ]# A tibble: 1 × 3
content_guid path created_time
<chr> <chr> <dttm>
1 154bd2af-e8fa-4aa4-aab8-dcef701f4af9 /my-dashboard/ 2024-08-01 20:44:58