Sync API
Examples
Python examples that send Microsoft Entra ID employees and Microsoft 365 licenses and usage to Viio and run them on AWS Lambda.
Last updated
These examples use the Viio Python SDK to send Microsoft data to Viio. Each script reads Microsoft Graph with a Microsoft Entra application and sends a complete snapshot in one batch. You can run the scripts from your workstation, any scheduler, or AWS Lambda.
Shared Setup
You need:
- Python 3.11 or later.
- A passive direct integration installation and its ID.
- A Viio API key with the
integration:syncpermission. - A Microsoft Entra application with a client secret. Grant it the Microsoft Graph application permissions that each example lists, with tenant-wide admin consent.
Install the SDK:
python -m pip install "viio-sync-api-sdk>=0.5.0"
Both scripts read the same environment variables:
| Variable | Description |
|---|---|
MICROSOFT_TENANT_ID | Microsoft Entra tenant ID or verified domain |
MICROSOFT_CLIENT_ID | Entra application client ID |
MICROSOFT_CLIENT_SECRET | Entra application client secret |
VIIO_SYNC_API_ENDPOINT | https://sync.viio.io |
VIIO_SYNC_API_KEY | Viio API key with integration:sync |
VIIO_DIRECT_INTEGRATION_INSTALLATION_ID | Installation that receives the data |
Supply secret values through your secret-management system. Do not commit them to source control.
Script Structure
Each script has the same three entry points:
| Function | Purpose |
|---|---|
sync_*(write) | Reads Microsoft Graph and passes every SyncRecordsRequest to write |
run_batch(sync) | Starts a batch, runs the sync function with batch.write, and completes the batch, or aborts it if anything fails |
main() | Command-line entry point; --dry-run prints the requests as JSON instead of sending them |
The AWS Lambda example imports run_batch and the sync functions.
Only one batch can be active for an installation at a time. If both scripts send to the same installation, schedule them so they don't overlap.
Learn the batch lifecycle