Graph API Client
Microsoft Graph gives you access to the wider Microsoft 365 ecosystem. You can enrich your application with data from across Microsoft 365.
The SDK gives your application easy access to the Microsoft Graph API via the microsoft-teams-graph package.
Calling APIs​
Microsoft Graph can be accessed by your application using its own application token, or by using the user's token. If you need access to resources that your application may not have, but your user does, you will need to use the user's scoped graph client. To grant explicit consent for your application to access resources on behalf of a user, follow the auth guide.
To access the graph using the Graph using the app, you may use the app.graph object to call the endpoint of your choice.
# Equivalent of https://learn.microsoft.com/en-us/graph/api/user-get
# Gets the details of the bot-user
user = await app.graph.me.get()
print(f"User ID: {user.id}")
print(f"User Display Name: {user.display_name}")
print(f"User Email: {user.mail}")
print(f"User Job Title: {user.job_title}")
You can also access the graph using the user's token from within a message handler via the user_graph property.
@app.on_message
async def handle_message(ctx: ActivityContext[MessageActivity]):
user = await ctx.user_graph.me.get()
print(f"User ID: {user.id}")
print(f"User Display Name: {user.display_name}")
print(f"User Email: {user.mail}")
print(f"User Job Title: {user.job_title}")
Here, the user_graph object is a scoped graph client for the user that sent the message.
You also have access to the app_graph object in the activity handler. This is equivalent to app.graph.