I need to know user emails and id (so I can identify the user from the email).
According to Microsoft documentation, the below code should allow the retrival of user information.
import asyncio
import configparser
from azure.identity.aio import ClientSecretCredential
from msgraph import GraphServiceClient
from msgraph.generated.users.item.user_item_request_builder import UserItemRequestBuilder
def main():
# Load settings
config = configparser.ConfigParser()
config.read(['config.cfg', 'config.dev.cfg'])
azure_settings = config['azure']
credentials = ClientSecretCredential(
azure_settings['tenantId'],
azure_settings['clientId'],
azure_settings['clientSecret'],
)
scopes = ['https://graph.microsoft.com/.default']
client = GraphServiceClient(credentials=credentials, scopes=scopes)
query_params = UserItemRequestBuilder.UserItemRequestBuilderGetQueryParameters(select=['id', 'mail', ])
request_config = UserItemRequestBuilder.UserItemRequestBuilderGetRequestConfiguration(query_parameters=query_params)
users = asyncio.run(client.users.get(request_config))
print(users)
However, I get the error
Traceback (most recent call last):
File "C:UsersPycharmProjectsProcessEmailReceiptsmicrosoft_graph.py", line 35, in <module>
main()
File "C:UsersPycharmProjectsProcessEmailReceiptsmicrosoft_graph.py", line 28, in main
request_config = UserItemRequestBuilder.UserItemRequestBuilderGetRequestConfiguration(query_parameters=query_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'UserItemRequestBuilder' has no attribute 'UserItemRequestBuilderGetRequestConfiguration'
Looking at the repo, that class does indeed not exists.
Is there a way to get all users id and emails with the python sdk?
Thanks,
Recognized by Microsoft Azure Collective