Associating and Using Multiple Integrations

Problem

You want to associate multiple integrations with your content and use them in your code.

Solution

Warning

You must have administrator or publisher privileges to find an integration.

Get your current content and use the associations.update() method to associate multiple integrations. You can get these GUIDs from the Dashboard in the System > Integrations screen by clicking on an integration in the table or get a list using the integrations.find() method.

from posit import connect

client = connect.Client()
content = client.content.get() # no params defaults to the currently running content
content.associations.update([
  "guid-1", # name: My first integration
  "guid-2", # name: My last integration
])

Next, in order to use these integrations in your content do the following:

from posit import connect

client = connect.Client()
content = client.content.get() # no params defaults to the currently running content

association1 = content.associations.find_by(guid="guid-1")
association2 = content.associations.find_by(name=r"last integration")

integration1_creds = client.oauth.get_credentials(user_session_token, audience=association1.get("oauth_integration_guid"))
integration2_creds = client.oauth.get_credentials(user_session_token, audience=association2.get("oauth_integration_guid"))

Get the objects representing your content and the integrations you wish to use, then use the set_integrations() function to associate them, allowing the content to call the integrations.

You can get content GUIDs from Connect’s Dashboard. When running on Connect, the environment variable CONNECT_CONTENT_GUID contains the current content GUID.

You can get integrations using their GUIDs (which you can find in the System > Integrations screen on Connect) or by filtering on other fields, such as their names or templates.

library(connectapi)

CONTENT_GUID <- "a080baef-854e-411f-ac3c-d2bc47bcb109"
INTEGRATION_GUIDS <- c("84f0f0ae-e328-44b0-98ba-aee6e775b5f0", "a0b52758-d0b5-4b27-a6c0-13ca07eabdd7")

client <- connect()

content <- content_item(client, CONTENT_GUID)

integrations <- get_integrations() |>
  purrr::keep(~ .x$guid %in% INTEGRATION_GUIDS)

set_integrations(content, integrations)

You can now use these integrations to get credentials in content running on Connect.

library(connectapi)

client <- connect()
this_content <- content_item(client, Sys.getenv("CONNECT_CONTENT_GUID"))

this_content_integrations <- get_integrations(client)

# Call `get_oauth_credentials()` with the GUIDs from each integration

integration1_creds <- get_oauth_credentials(client, user_session_token, audience = integrations[[1]]$guid)
integration2_creds <- get_oauth_credentials(client, user_session_token, audience = integrations[[2]]$guid)

See also