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.

Microsoft Entra ID

Send Entra ID users as a complete employee snapshot.

Microsoft Licenses

Send Microsoft 365 plans with their service plans and subscriptions, the accounts and licenses assigned to them, and each user's app usage.

AWS Lambda

Run both syncs on a schedule from 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:sync permission.
  • 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:

VariableDescription
MICROSOFT_TENANT_IDMicrosoft Entra tenant ID or verified domain
MICROSOFT_CLIENT_IDEntra application client ID
MICROSOFT_CLIENT_SECRETEntra application client secret
VIIO_SYNC_API_ENDPOINThttps://sync.viio.io
VIIO_SYNC_API_KEYViio API key with integration:sync
VIIO_DIRECT_INTEGRATION_INSTALLATION_IDInstallation 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:

FunctionPurpose
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