Associating Integrations with Content

Problem

You want to associate an integration with a content item. See Associating and Using Multiple Integrations for an example using multiple integrations.

Note

Updating the integrations associated with a piece of content replaces any existing associations with the newly supplied integrations.

Solution

Get a content item and an integration, then use the content item’s oauth.associations.update() method to associate them.

from posit import connect

CONTENT_GUID = "a080baef-854e-411f-ac3c-d2bc47bcb109"
INTEGRATION_GUID = "84f0f0ae-e328-44b0-98ba-aee6e775b5f0"

client = connect.Client()
content = client.content.get(CONTENT_GUID)
content.oauth.associations.update(INTEGRATION_GUID)

Get the connectapi objects representing the piece of content and integration you wish to associate. Then, use the set_integrations() function to apply the integration to the content item. You can pass in either a single integration object or a list of such objects.

library(jsonlite)
library(connectapi)

CONTENT_GUID <- "a080baef-854e-411f-ac3c-d2bc47bcb109"
INTEGRATION_GUID <- "84f0f0ae-e328-44b0-98ba-aee6e775b5f0"

client <- connect()

content <- content_item(client, CONTENT_GUID)
integration <- get_integration(client, INTEGRATION_GUID)

set_integrations(content, integration)

Discussion

To view the newly created association follow the Finding Associations by Content recipe.

See also