Skip to content
Bifrost Docs

Integrations Module

SDK reference for accessing integration configurations and OAuth tokens

The integrations module provides access to integration configurations and OAuth credentials.

from bifrost import integrations

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 | None
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)
  • None explicitly: 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".

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.

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_id

For setup steps, see Add a Named Integration Instance.

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] | None
mappings = await integrations.list_mappings("HaloPSA")
if mappings:
for mapping in mappings:
print(f"Org: {mapping.organization_id}, Entity: {mapping.entity_id}")

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 | None
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
# Get by scope
mapping = await integrations.get_mapping("HaloPSA", scope="org-123")
# Get by entity_id
mapping = await integrations.get_mapping("HaloPSA", entity_id="tenant-456")
if mapping:
print(f"Entity: {mapping.entity_id}, Config: {mapping.config}")

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 | None

The 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.

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,
) -> IntegrationMappingResponse
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
mapping = await integrations.upsert_mapping(
"HaloPSA",
scope="org-123",
entity_id="tenant-456",
entity_name="Acme Corp",
config={"custom_field": "value"}
)

Delete an organization mapping for an integration.

async def delete_mapping(
name: str,
scope: str,
*,
instance: str | None = None,
) -> bool
Parameter Type Description
name str Integration name
scope str Organization ID (required)
deleted = await integrations.delete_mapping("HaloPSA", scope="org-123")
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 | None
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) -> OAuthCredentials

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 token

This 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.

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: datetime
from bifrost import workflow, integrations
import httpx
@workflow
async 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()

Integration config is merged from two levels:

  1. Integration defaults - Platform-wide defaults
  2. Organization overrides - Per-org customizations

The config dict in IntegrationData contains the merged result.

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}"})