Would you like a list of all users in your organization? Including email, name, phone, etc? At the mere push of a button?
The Microsoft Graph API may help with this wish. Add a sprinkle of Python and you can automate this process leaving you to do other important and eh … fun things like … documentation?
I’ve written a script that helps you access all user data in your organization. You could use this script in a serverless computing solution like Azure Functions or AWS Lambda Function. Schedule the script and BAM:
You have (part of) your DimEmployee ready to be used!
In order to make your life easier I created a step-by-step tutorial. Check it out below!
Bezig met laden…
import requests
import json
import auth
# Get an access token from Microsoft Identity platform
tenant_id = auth.tenant_id
client_id = auth.client_id
client_secret = auth.client_secret
authority_url = f"https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token"
body = {
"grant_type": "client_credentials",
"client_id": client_id,
"client_secret": client_secret,
"scope": "https://graph.microsoft.com/.default",
}
token_response = requests.post(authority_url, data=body)
token = token_response.json().get('access_token')
# Use the token to make an API request
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
# API call to get all users
url = "https://graph.microsoft.com/v1.0/users"
response = requests.get(url, headers=headers)
# Print the result
users = response.json()
print(json.dumps(users, indent=4))