Organizing Content
This section explains how to use the Connect Server APIs to organize your content using tags and vanity URLs. See the Deploying Content section for help creating and deploying content, and the Managing Content section for help discovering and managing existing content.
These recipes use bash snippets and rely on curl to perform HTTP requests. We use the CONNECT_SERVER and CONNECT_API_KEY environment variables introduced in the Getting Started section of this cookbook.
Vanity URLs
Vanity URLs allow you to assign custom paths to content items, providing more memorable and descriptive paths to your popular content items. Vanity URLs also let you take advantage of advanced deployment strategies such as Blue-Green Deployments.
You can find the full reference of vanity-related API endpoints in the Posit Connect API Reference.
Setting a Vanity URL for a Content Item
If you’d like to set a vanity URL for a specific content item, you should use the PUT /v1/content/{guid}/vanity endpoint.
A content item may only have one vanity URL. Likewise, a unique vanity URL may only correspond to one content item. If you’d like to re-assign a vanity URL within a single API call, you can use the force parameter as outlined in the API Reference docs.
export DATA='{"path": "/shakespeare/"}'
curl --silent --show-error -L --max-redirs 0 --fail -X PUT \
-H "Authorization: Key ${CONNECT_API_KEY}" \
--data "${DATA}" \
"${CONNECT_SERVER}__api__/v1/content/ccbd1a41-90a0-4b7b-89c7-16dd9ad47eb5/vanity"
# => {
# => "content_guid": "ccbd1a41-90a0-4b7b-89c7-16dd9ad47eb5",
# => "path": "/shakespeare/",
# => ...
# => }Getting a Vanity URL for a Content Item
You can easily fetch the vanity URL for a specific content item as well using the GET /v1/content/{guid}/vanity endpoint.
curl --silent --show-error -L --max-redirs 0 --fail -X GET \
-H "Authorization: Key ${CONNECT_API_KEY}" \
"${CONNECT_SERVER}__api__/v1/content/ccbd1a41-90a0-4b7b-89c7-16dd9ad47eb5/vanity"
# => {
# => "content_guid": "ccbd1a41-90a0-4b7b-89c7-16dd9ad47eb5",
# => "path": "/shakespeare/",
# => ...
# => }If there is no vanity URL set, you will receive a 404 HTTP status code.
Removing a Vanity URL from a Content Item
Also, you can remove a vanity URL from a content item using the DELETE /v1/content/{guid}/vanity endpoint.
curl --silent --show-error -L --max-redirs 0 --fail -X DELETE \
-H "Authorization: Key ${CONNECT_API_KEY}" \
"${CONNECT_SERVER}__api__/v1/content/ccbd1a41-90a0-4b7b-89c7-16dd9ad47eb5/vanity"
# =>A successful request will return a 204 HTTP status code with an empty response.
Listing All Vanity URLs
Lastly, you may want to list all vanity URLs across all content on the Connect server. This can be useful for auditing or searching for content by URL. The GET /v1/vanities endpoint provides this functionality.
curl --silent --show-error -L --max-redirs 0 --fail -X GET \
-H "Authorization: Key ${CONNECT_API_KEY}" \
"${CONNECT_SERVER}__api__/v1/vanities"
# => [
# => {
# => "content_guid": "ccbd1a41-90a0-4b7b-89c7-16dd9ad47eb5",
# => "path": "/shakespeare/",
# => ...
# => },
# => ...
# => ]