Locking and Unlocking Content
Problem
You need to lock or unlock content. For example, you might want to lock an old application that has been superseded by a new one, using the lock message to forward visitors to the new application. For details on the effects of locking content, see the Content Settings Panel documentation.
Solution
Use the Python SDK or the connectapi R package to lock or unlock content.
To lock content, invoke the update method on a piece of content, passing in locked=True and an optional locked_message.
from posit import connect
CONTENT_GUID = "154bd2af-e8fa-4aa4-aab8-dcef701f4af9"
client = connect.Client()
content = client.content.get(CONTENT_GUID)
content.update(
    locked=True,
    locked_message="No longer maintained, please use the [new application](https://connect.example/new-application)."
)To unlock content, call update with locked=False.
content.update(locked=False)To lock content, use the lock_content() function on a piece of content, optionally providing a locked_message.
library(connectapi)
CONTENT_GUID <- "65d02ea5-2e26-436a-afe3-4ef98a8ba8fc"
client <- connect()
content <- search_content(client, CONTENT_GUID)[[1]]
content <- lock_content(
  content,
  "No longer maintained, please use the [new application](https://connect.example/new-application)."
)To lock multiple pieces of content with one call — in this example, all content from a specified user — you can use purrr::map or lapply to iterate over a list of content.
USERNAME <- "publisher1"
content_list <- search_content(client, paste0("owner:", USERNAME))
content_list <- purrr::map(content_list, lock_content, locked_message = "publisher1's content is deprecated.")To unlock content, call unlock_content() on a piece of content.
unlocked <- unlock_content(content_list[[1]])See also
- For more information on locking and unlocking content, see the Content Settings Panel documentation.