Integrations Module
SDK reference for accessing integration configurations and OAuth tokens
The integrations module provides access to integration configurations and OAuth credentials.
Import
Section titled “Import”from bifrost import integrationsMethods
Section titled “Methods”integrations.get()
Section titled “integrations.get()”Get integration configuration with OAuth tokens.
async def get( name: str, scope: str | None = None, oauth_scope: str | None = None, *, instance: str | None = None, on_missing: Literal["fail", "default"] = "fail",) -> IntegrationData | NoneParameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
name |
str | Integration name (e.g., “HaloPSA”, “Microsoft_Graph”) |
scope |
str | None | Organization scope (see below) |
oauth_scope |
str | None | Request a fresh token with a different scope in a client credentials flow. |
instance |
str | None | Stable instance key. Omit to use the Default connection. |
on_missing |
"fail" or "default" |
A missing named instance returns a 404 by default. Use "default" to explicitly use Default if that instance key is absent. |
Scope parameter:
- (omitted) (default): Use execution context’s org, with automatic global fallback via cascade
- Org UUID string: Target specific organization (provider orgs only)
Noneexplicitly: Target global scope directly (integration defaults only)
Note: Targeting a specific org via UUID requires provider org context. Managed orgs can only access their own scope. Use
context.set_scope()to override scope for all calls at once.
Bifrost resolves organization mappings and configuration defaults within the selected instance. Permission, credential, and OAuth errors still propagate when on_missing="default".
Returns
Section titled “Returns”IntegrationData includes the selected connection’s instance_key. If the integration definition is absent, the call returns None unless the executing Solution declares the integration as required. In that case it returns a 424 error.
Example
Section titled “Example”integration = await integrations.get("Microsoft_Graph")if integration: # Access OAuth tokens token = integration.oauth.access_token
# Access config values tenant_id = integration.config.get("tenant_id")
# Entity ID for multi-tenant entity = integration.entity_idFor setup steps, see Add a Named Integration Instance.
integrations.list_mappings()
Section titled “integrations.list_mappings()”List the organization mappings the caller can read for an integration instance. The optional scope argument is accepted for compatibility. Mapping methods use the Default connection when instance is omitted.
async def list_mappings( name: str, scope: str | None = None, *, instance: str | None = None,) -> list[IntegrationMappingResponse] | NoneExample
Section titled “Example”mappings = await integrations.list_mappings("HaloPSA")if mappings: for mapping in mappings: print(f"Org: {mapping.organization_id}, Entity: {mapping.entity_id}")integrations.get_mapping()
Section titled “integrations.get_mapping()”Get a specific organization mapping for an integration.
async def get_mapping( name: str, scope: str | None = None, entity_id: str | None = None, *, instance: str | None = None,) -> IntegrationMappingResponse | NoneParameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
name |
str | Integration name |
scope |
str | None | Organization scope (see below) |
entity_id |
str | External entity ID to filter by |
Scope parameter:
None(default): Use execution context’s organization- Org UUID string: Target specific organization
Example
Section titled “Example”# Get by scopemapping = await integrations.get_mapping("HaloPSA", scope="org-123")
# Get by entity_idmapping = await integrations.get_mapping("HaloPSA", entity_id="tenant-456")
if mapping: print(f"Entity: {mapping.entity_id}, Config: {mapping.config}")integrations.find_mapping()
Section titled “integrations.find_mapping()”Find a mapping by exact external entity ID among the mappings the caller can read.
async def find_mapping( name: str, entity_id: str, *, instance: str | None = None,) -> IntegrationMappingFindResult | NoneThe result status is unique, ambiguous, or not_found_in_authorized_scope. Only a unique result includes a mapping. A miss describes the caller’s authorized scope.
integrations.upsert_mapping()
Section titled “integrations.upsert_mapping()”Create or update an organization mapping for an integration.
async def upsert_mapping( name: str, scope: str, # Required entity_id: str, entity_name: str | None = None, config: dict | None = None, *, instance: str | None = None,) -> IntegrationMappingResponseParameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
name |
str | Integration name |
scope |
str | Organization ID (required) |
entity_id |
str | External entity ID (tenant, company, etc.) |
entity_name |
str | Display name for the entity |
config |
dict | Organization-specific configuration overrides |
Example
Section titled “Example”mapping = await integrations.upsert_mapping( "HaloPSA", scope="org-123", entity_id="tenant-456", entity_name="Acme Corp", config={"custom_field": "value"})integrations.delete_mapping()
Section titled “integrations.delete_mapping()”Delete an organization mapping for an integration.
async def delete_mapping( name: str, scope: str, *, instance: str | None = None,) -> boolParameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
name |
str | Integration name |
scope |
str | Organization ID (required) |
Example
Section titled “Example”deleted = await integrations.delete_mapping("HaloPSA", scope="org-123")IntegrationData
Section titled “IntegrationData”class IntegrationData(BaseModel): integration_id: str definition_id: str | None = None instance_key: str | None = None entity_id: str | None # External entity ID (tenant, company, etc.) entity_name: str | None # Display name for entity config: dict # Merged configuration (defaults + org overrides) oauth: OAuthCredentials | NoneOAuthCredentials
Section titled “OAuthCredentials”class OAuthCredentials(BaseModel): connection_name: str client_id: str | None client_secret: str | None # Decrypted authorization_url: str | None token_url: str | None scopes: list[str] access_token: str | None # Decrypted refresh_token: str | None # Decrypted expires_at: str | None # ISO format
async def refresh(self) -> OAuthCredentialsoauth.refresh()
Section titled “oauth.refresh()”Programmatically refresh the OAuth token. Works for both client_credentials and authorization_code flows. Updates access_token and expires_at in-place and persists the new token to the database.
integration = await integrations.get("Pax8")await integration.oauth.refresh()# integration.oauth.access_token is now a fresh tokenThis is useful when a provider’s tokens expire before their stated expires_in duration, or when you need to guarantee a fresh token before a critical API call.
IntegrationMappingResponse
Section titled “IntegrationMappingResponse”class IntegrationMappingResponse(BaseModel): id: str integration_id: str definition_id: str | None = None instance_key: str | None = None organization_id: str entity_id: str | None entity_name: str | None oauth_token_id: str | None config: dict created_at: datetime updated_at: datetimeUsage Pattern
Section titled “Usage Pattern”from bifrost import workflow, integrationsimport httpx
@workflowasync def sync_users(): # Get integration with OAuth msft = await integrations.get("Microsoft_Graph") if not msft or not msft.oauth: return {"error": "Integration not configured"}
# Use the access token async with httpx.AsyncClient() as client: response = await client.get( "https://graph.microsoft.com/v1.0/users", headers={"Authorization": f"Bearer {msft.oauth.access_token}"} ) return response.json()Configuration Merging
Section titled “Configuration Merging”Integration config is merged from two levels:
- Integration defaults - Platform-wide defaults
- Organization overrides - Per-org customizations
The config dict in IntegrationData contains the merged result.
Token Handling
Section titled “Token Handling”OAuth tokens are:
- Encrypted at rest in the database
- Automatically decrypted when retrieved via SDK
- Refreshed automatically by the platform when expired
If a token is rejected before its stated expiry (common with some providers like Pax8), use oauth.refresh() to fetch a fresh token on demand:
integration = await integrations.get("Pax8")
response = await client.get(url, headers={"Authorization": f"Bearer {integration.oauth.access_token}"})if response.status_code == 401: await integration.oauth.refresh() response = await client.get(url, headers={"Authorization": f"Bearer {integration.oauth.access_token}"})See Also
Section titled “See Also”- Integrations Overview - Concept guide
- Creating Integrations - Setup guide