Associating and Using Multiple Integrations
Problem
You want to associate multiple integrations with your content and use them in your code.
Solution
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
= connect.Client()
client = client.content.get() # no params defaults to the currently running content
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
= connect.Client()
client = client.content.get() # no params defaults to the currently running content
content
= content.associations.find_by(guid="guid-1")
association1 = content.associations.find_by(name=r"last integration")
association2
= client.oauth.get_credentials(user_session_token, audience=association1.get("oauth_integration_guid"))
integration1_creds = client.oauth.get_credentials(user_session_token, audience=association2.get("oauth_integration_guid")) integration2_creds
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)
<- "a080baef-854e-411f-ac3c-d2bc47bcb109"
CONTENT_GUID <- c("84f0f0ae-e328-44b0-98ba-aee6e775b5f0", "a0b52758-d0b5-4b27-a6c0-13ca07eabdd7")
INTEGRATION_GUIDS
<- connect()
client
<- content_item(client, CONTENT_GUID)
content
<- get_integrations() |>
integrations ::keep(~ .x$guid %in% INTEGRATION_GUIDS)
purrr
set_integrations(content, integrations)
You can now use these integrations to get credentials in content running on Connect.
library(connectapi)
<- connect()
client <- content_item(client, Sys.getenv("CONNECT_CONTENT_GUID"))
this_content
<- get_integrations(client)
this_content_integrations
# Call `get_oauth_credentials()` with the GUIDs from each integration
<- get_oauth_credentials(client, user_session_token, audience = integrations[[1]]$guid)
integration1_creds <- get_oauth_credentials(client, user_session_token, audience = integrations[[2]]$guid) integration2_creds
See also
- For more details about the data returned in this recipe, see List all associations for this OAuth integration in the API Reference.
- For more details about using the
audience
parameter with multiple associated integrations, see Exchange Connect credentials for OAuth credentials in the API Reference. - See OAuth Integrations in the User Guide to learn more about how publishers and viewers interact with OAuth integrations.
- See OAuth Integrations in the Admin Guide to for more detailed information on how to configure OAuth integrations.