Assigning Tags
Problem
You want to assign a tag to a content item.
Solution
Tip
A tag must be created before it can be assigned to content.
Warning
You must have administrator privileges to assign a tag.
To assign a tag, you need:
- The unique identifier (GUID) for the content item you want to tag. See Content recipes, or copy the GUID from the Info pane in the Connect Dashboard.
- The identifier for the tag you want to use. See Find tags recipe for details.
from posit import connect
= 'your-content-item-guid'
CONTENT_GUID = "your-tag-id"
TAG_ID
= connect.Client()
client
f"/v1/content/{CONTENT_GUID}/tags", json={
client.post('tag_id': TAG_ID,
})
To assign a tag, you need:
- The unique identifier (GUID) for the content item you want to tag. See Content recipes, or copy the GUID from the Info pane in the Connect Dashboard.
- The name or identifier for the tag you want to use. See Find tags recipe for details.
The set_content_tags()
function in connectapi
can take multiple tag objects to set multiple tags at once.
library(connectapi)
<- connect()
client
# Create an object representing the content you wish to update.
<- "154bd2af-e8fa-4aa4-aab8-dcef701f4af9"
CONTENT_GUID <- get_content(client, guid = CONTENT_GUID)
target_content
# Get the tags from the Connect server, then specify the tag you wish to apply
# to the content.
<- get_tags(client)
tags <- tags$category$my_tag
target_tag
<- set_content_tags(content = target_content, tag = target_tag) target_content
When called, set_content_tags()
prints out the updated tag tree. It returns an object representing the updated content item.
> target_content <- set_content_tags(target_content, target_tag)
Tree (target_content)
Posit Connect Tag
└── category
└── my_tag
> target_content
:
Posit Connect Content: 154bd2af-e8fa-4aa4-aab8-dcef701f4af9
Content GUID: https://connect.example.org/connect/#/apps/154bd2af-e8fa-4aa4-aab8-dcef701f4af9/
Content URL: Example Content
Content Title
content_item(client, guid = "154bd2af-e8fa-4aa4-aab8-dcef701f4af9")