The best approach to managing users and their attributes is to derive them from an SSO system, and Omni supports many systems through its SAML and SCIM such as Okta, Active Directory and more.
But sometimes you have a need to bulk create users in a pinch, update user attributes, or even occasionally delete if needed.
The Python SDK now supports the api endpoints to make bulk admin a piece of cake .
You can see the script for performing these updates here. But we’ll walk through the setup step by step.
First, install the python SDK. You may want to create a virtual environment first.
Optional Step 0 - Create a virtual environment
Starting in a folder you’d like the script to live in. Double check you have at least python 3.9+
python -m venv ./.venv
Activate the virtual environment:
source ./.venv/bin/activate
Step 1 - Pip install the sdk
pip install omni_python_sdk
Step 2 - Create the script and fill out API key and Omni Host
from omni_python_sdk import OmniAPI
import csv, time
api_key = '<<your api key>>'
base_url = 'https://<<your omni host>>'
# Initialize the API with your credentials
api = OmniAPI(api_key, base_url)
with open('users.csv', newline='') as csvfile:
spamreader = csv.DictReader(csvfile)
for row in spamreader:
time.sleep(2)
email = row.pop('email')
displayName = row.pop('display_name')
op = row.pop('op')
if op == 'upsert':
r1 = api.upsert_user(
email=email,
displayName=displayName,
attributes=row
)
elif op == 'delete':
api.delete_user(email)
Step 3 - Set up your CSV
- The
op
column should either be upsert, which will create a user if they do not exist, and will refresh their user attributes if they do. Delete will delete the user. Records are identified by email - The column names after display_name should be exactly the user attribute’s reference, which you can find in Omni in settings > attributes
- multi-value user attributes should be enclosed in
[...]
square brackets, if not they will fail.
Step 4 – Run it
python <<name of your script>>.py
It will pause 2 seconds in between each update to ensure it doesn’t hit the API throttle, and will provide little messages after each operation.
That’s it! You may want to schedule it, or run periodically. The upsert is idempotent.