Get all connected accounts for an entity

from composio import ComposioToolSet, App
toolset = ComposioToolSet()

# Filter based on entity id
entity = toolset.get_entity(id="default")
try:
    # Lists all connections of the entity
    connected_accounts  = entity.get_connections() 
    print(connected_accounts)
except NoItemsFound as e:
    print("No connected account found")

Check if an entity has a connected account for a particular app

from composio import ComposioToolSet, App
from composio.client.exceptions import NoItemsFound

toolset = ComposioToolSet()

# Filter based on entity id
entity = toolset.get_entity(id="default") 

try:
    # Filters based on app name
    connection_details = entity.get_connection(app=App.GITHUB) 
    # Filters based on connected account id for an entity
    connection_details = entity.get_connection(connected_account_id="<connected_account_id>") 
    print(connection_details)
except NoItemsFound as e:
    print("No connected account found")

Fetch the Connection Parameters

You can use connection parameters locally to build custom actions. The following parameters are typically available:

  • status: Current state of the connection (initiated, active, or failed)
  • refresh_token: Token used to obtain new access tokens
  • expires_in: Token expiration time in seconds
  • token_type: Type of token (usually “Bearer”)
  • base_url: Base URL for API requests
  • Additional parameters specific to the connected service
connected_account = toolset.get_connected_account(connection_request.connectedAccountId)

# Get the parameters for your local usage
print(toolset.get_auth_params(connection_id=connected_account.id))

#print(connected_account.connectionParams) # use this for raw/advanced cases

Example of how connection params would look like

{
	"base_url": "", // This is the base URL for the API Ex. https://api.linear.app
	"params": [{ // This is the list of all the params
		"name": "x-api-key", 
		"in": "header", // `in` value could be of type `header`, `query` 
		"value": "<api-key>"
	}],
	"body": {}
}

You can fetch connection details after user is redirected back to your app (If redirect was needed) and connectionStatus & connectedAccountId will be available in the query params.