Deleting All Sessions for an Integration

Problem

You want to delete all sessions for a given integration.

Solution

Iterate over a list of all existing sessions and delete the ones matching the given integration.

Warning

You must have administrator privileges to use this recipe.

Follow the Finding Sessions recipe to get all existing sessions, then iterate over the list and use the session’s delete() method to delete the session that matches the integration.

from posit import connect

INTEGRATION_GUID = "d24b4651-29a5-4555-b0f3-b5989bfe40fe"

client = connect.Client()
session = client.oauth.sessions.find(all=True)
for session in sessions:
        if session.oauth_integration_guid == INTEGRATION_GUID:
                session.delete()

Follow the Finding Sessions recipe to get all existing sessions, then use the connectapi client to make a direct call to the sessions endpoint to delete the session that matches the integration.

library(connectapi)
library(glue)
library(purrr)

INTEGRATION_GUID <- "d24b4651-29a5-4555-b0f3-b5989bfe40fe"

client <- connect()
sessions <- client$GET("v1/oauth/sessions?all=true")

for (session in sessions) {
  if (session$oauth_integration_guid == INTEGRATION_GUID) {
    client$DELETE(glue("v1/oauth/sessions/{session$guid}"))
  }
}

See also

  • For more details about the data returned in this recipe, see Delete an OAuth session 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.