Skip to content

SanaAI Source

The SanaAI source extracts insight reports from Sana’s learning platform using the query-based reporting API.

The SanaAI source ships with the core package; no extra is needed.

Terminal window
pip install bizon
name: sana-pipeline
source:
name: sana_ai
stream: insight_report
domain: your-company
query: "SELECT * FROM users WHERE active = true"
authentication:
type: oauth
params:
token_refresh_endpoint: https://your-company.sana.ai/api/token
client_id: ${env://SANA_CLIENT_ID}
client_secret: ${env://SANA_CLIENT_SECRET}
grant_type: client_credentials
access_token_name: accessToken
expires_in_name: expiresIn
response_field_path: data
scopes:
- read
- write
destination:
name: bigquery
config:
project_id: my-project
dataset_id: learning
gcs_buffer_bucket: my-bucket
StreamDescriptionIncremental
insight_reportQuery-based insight reportsNo
FieldTypeRequiredDescription
domainstringYesSana instance domain (e.g., company for company.sana.ai)
querystringYesSQL-like query for the insight report
report_job_max_wait_secondsintNoFail if the report job hasn’t succeeded after this many seconds (default 600)
httpobjectNoHTTP policy (default: (10, 60) timeout, retries on 429/5xx)

SanaAI uses OAuth2 client credentials. Sana’s token endpoint returns accessToken / expiresIn under data, hence the extra params:

source:
name: sana_ai
stream: insight_report
domain: your-company
query: "SELECT * FROM users"
authentication:
type: oauth
params:
token_refresh_endpoint: https://your-company.sana.ai/api/token
client_id: ${env://SANA_CLIENT_ID}
client_secret: ${env://SANA_CLIENT_SECRET}
grant_type: client_credentials
access_token_name: accessToken
expires_in_name: expiresIn
response_field_path: data
scopes:
- read
- write

To get OAuth credentials:

  1. Contact your Sana administrator
  2. Request API access with OAuth credentials
  3. You’ll receive a client_id and client_secret

The SanaAI source uses an asynchronous job pattern:

  1. Create Job: Submits a query to create an insight report job
  2. Poll Status: Polls the job status every 3 seconds until it succeeds
  3. Download Results: Downloads the CSV results when ready
  4. Parse Data: Parses CSV into records

The run fails with a SanaReportJobError if the job reports failed, or if it is still pending after report_job_max_wait_seconds. Raise the limit for reports that take longer than 10 minutes to generate.

name: sana-user-activity
source:
name: sana_ai
stream: insight_report
domain: acme-corp
query: |
SELECT
user_id,
email,
course_completions,
last_activity_date
FROM user_activity
WHERE last_activity_date >= '2024-01-01'
authentication:
type: oauth
params:
token_refresh_endpoint: https://acme-corp.sana.ai/api/token
client_id: ${env://SANA_CLIENT_ID}
client_secret: ${env://SANA_CLIENT_SECRET}
grant_type: client_credentials
access_token_name: accessToken
expires_in_name: expiresIn
response_field_path: data
scopes:
- read
- write
destination:
name: bigquery
config:
project_id: my-project
dataset_id: learning
dataset_location: US
gcs_buffer_bucket: my-staging-bucket

The query field accepts Sana’s insight query syntax. Consult your Sana documentation for available tables and fields.

Example queries:

-- All users
SELECT * FROM users
-- Active users with completions
SELECT user_id, email, course_completions
FROM users
WHERE active = true
-- Course progress
SELECT course_id, user_id, progress, completed_at
FROM course_progress
WHERE completed_at IS NOT NULL

Records are returned as CSV rows converted to dictionaries. The schema depends on your query’s SELECT columns.

Example record for SELECT user_id, email, name FROM users:

FieldDescription
user_idUser ID
emailUser email
nameUser name

Process insight data:

transforms:
- label: normalize-fields
python: |
data = {
'user_id': data.get('user_id'),
'email': data.get('email', '').lower(),
'name': data.get('name'),
'is_active': data.get('active', '').lower() == 'true'
}