Edit

Share via


Extend Python apps with more Microsoft Graph APIs

In this article, you add your own Microsoft Graph capabilities to the application you created in Build Python apps with Microsoft Graph. For example, you might want to add a code snippet from Microsoft Graph documentation or Graph Explorer, or code that you created. This section is optional.

Update the app

  1. Add the following function to graph.py.

    async def make_graph_call(self):
        # INSERT YOUR CODE HERE
        return
    
  2. Replace the empty make_graph_call function in main.py with the following.

    async def make_graph_call(graph: Graph):
        await graph.make_graph_call()
    

Choose an API

Find an API in Microsoft Graph you'd like to try. For example, the Create event API. You can use one of the examples in the API documentation, or create your own API request.

Configure permissions

Check the Permissions section of the reference documentation for your chosen API to see which authentication methods are supported. Some APIs don't support app-only, or personal Microsoft accounts, for example.

  • To call an API with user authentication (if the API supports user (delegated) authentication), add the required permission scope in config.cfg.
  • To call an API with app-only authentication, see the app-only authentication tutorial.

Add your code

Copy your code into the make_graph_call function in graph.py. If you're copying a snippet from documentation or Graph Explorer, be sure to rename the GraphServiceClient to self.user_client.

Now that you have a working app that calls Microsoft Graph, you can experiment and add new features.

Python samples