Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In this article, you add your own Microsoft Graph capabilities to the application you created in Build .NET 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.
Update the app
Open ./GraphHelper.cs and add the following function to the GraphHelper class.
// This function serves as a playground for testing Graph snippets // or other code public async static Task MakeGraphCallAsync() { // INSERT YOUR CODE HERE }
Replace the empty
MakeGraphCallAsync
function in Program.cs with the following.async Task MakeGraphCallAsync() { await GraphHelper.MakeGraphCallAsync(); }
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 you can customize an API request in Graph Explorer and use the generated snippet.
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 appsettings.json.
- To call an API with app-only authentication, see the app-only authentication tutorial.
Add your code
Copy your code into the MakeGraphCallAsync
function in GraphHelper.cs. If you're copying a snippet from documentation or Graph Explorer, be sure to rename the GraphServiceClient
to _userClient
.
Related content
Now that you have a working app that calls Microsoft Graph, you can experiment and add new features.
- Learn how to use app-only authentication with the Microsoft Graph .NET SDK.
- Visit the Overview of Microsoft Graph to see all of the data you can access with Microsoft Graph.