Demo - Create, update, and delete users with the Microsoft Graph

Microsoft 365 Developer · Intermediate ·📰 AI News & Updates ·4y ago

Key Takeaways

This video demonstrates how to create, update, and delete users in an organization using Microsoft Graph, with a focus on modifying an existing Azure AD app and .NET Core console app to use the necessary permissions and API calls.

Full Transcript

in this demo i'm going to modify the existing azure ad app and net core console app to use microsoft graph to both create update and delete users within my organization now this assumes that i've already created the azure ad app and net core console app from the previous demos in this module which i already have done so the first step is to go to the azure ad app and grant it a new permission so i'm going to go to our app our app registrations i'm going to find my graph console app i'm going to go to the api permissions so i want to add in a new permission it's a microsoft graph delegated permission and this is the user.read write.all and then i'll say add permissions and then i'm going to select the grant admin consent as i've done previously now once that's done let's come back over to our code and i need to find the place where i'm requesting permissions so right here user.read.all we're going to update this to say user.readright.all so i can actually make changes to it now we can go modify our code so what i'm going to do is i'm going to find the part where we're getting the authenticated client and get rid of all the other code from my previous demo now one thing i'm going to need to do with this and i'm also going to need to add a using statement so i'm going to add using system dot threading dot tasks because we're going to have an asynchronous task now the first step that we're going to do is we're going to create a user so i'm going to add in this code to create a brand new user and we need to have a function that we're going to have to define called create user async when that runs we're going to wait for it to finish creating the user and then it's going to write out the new user's id so let's go add a method to go create that user so i'm going to scroll down we'll add it right before or right after the main the main method all right so what is create user async doing is creating a new user object and specifying a little bit of information about them melissa darrow we can see her name we can see your nickname and a user profile name now one of the things i need to do is i need to also update her domain her organization domain to be equal to the same domain that we're currently working with so i'm just going to go ahead and grab the one for the current user and just sign that in using my temporary uh microsoft 365 developer tenant account so just to show that we don't already have this user already added i'm going to come over here to the users collection inside of azure id we're going to search for melissa and we don't have any melissa's listed so let's go back to our application we'll open up the console and let's go do a let's go ahead and execute the code so we'll do that by doing a net build and we need to get the entire user so we'll go log in as the current user we'll also grab the password and we'll create the user so it shows a new user was has been created so let's go back over to azure id to ensure that user was created i'll refresh the page and we'll do another search for melissa and sure enough now we see that melissa has been created so if i go ahead and open this up you can see i can scroll through and i can see some information about the current user so what i want you to notice with the new user we just created take a look at the mobile the mobile phone for melissa notice that there's no mobile phone listed for melissa darrow what we're going to do is we're going to update the code to set her pro her mobile phone number so i'm going to come back over here to the code and what i'm going to do is we're going to get a reference to the user that we just created so let's get rid of the code to create a user so now we're going to update the user so first i want to find the user that we just created so that was melissa darrow and again we need to make sure we pass in her the correct org or the domain for her we're going to get that user and then i'm going to call a method called update user async and we're going to wait for that to finish so let's go add that method for updating the user async and what we're doing is we're going to take the we're going to create a new instance of that user uh user object and we're going to pass in the mobile phone now what we're doing here we're passing in the id of the user we want to update and then we're only passing in a user object that contains the properties that we want to change so here we're only passing in the mobile phone property is the only property that i want to change so now let's go ahead and run this so do a netbuild.net run so go ahead and log in there we go it should have updated the user so let's go back over to azure id this can take a second for the mobile phone to show up so let's see how fast it happens and now we see the mobile phone has been updated with the number that we specified so it took a minute but it did actually show up that's just a propagation thing the last thing that we can do is we can delete the user so in this section we're going to update the code to delete the user that we created in the previous section so what i'm going to do is come back over to the code and in the part where we are updating the user we already have the user so what i'm going to do is we're going to pass in the code that we want to delete the user so after the user we updated them so now come over here and we'll say we'll delete them so here's the user to update we're passing in their id and we need a method here that we're going to define to delete the user and i'll do that by passing in this delete method or pasting in this delete method you can see here that in order to delete all we're doing is we're calling the delete async method on the request object that's returned and then we're going to wait for that to complete so again let's test this out i'll do a net build go ahead and log in wait for it to finish and once it's finished we'll come back over to edge and let's refresh the page and try and find our user and we can see now that the user is not found because they've been deleted if i come back over here to the dashboard for all my users or go to the users page and do a search for melissa you can see she's showing up but it's still taking a second for it to get sync but we can see that the user has actually been deleted so it's just taking a second for azure id to update the ux so in this demo you saw how we modified the existing azure ad app and the net console app and used microsoft graph to create update and delete users in the organization thank you for watching i hope you've learned something now remember that this video is part of a series of videos on this microsoft learning module this video is also part of a playlist that includes all the videos that are associated with this module so that you can watch them in order the playlist and all its included videos are associated with a microsoft learning module that includes hands-on lab exercises and additional resources check the notes for this video and the associated playlist for more information and where to find the microsoft learning module

Original Description

In this demo, you’ll learn how to create, update, and delete users in your organization and the permissions required to do these operations with Microsoft Graph. This video is part of a series in a playlist and is associated with a Microsoft Learning module: 'Access User Data from Microsoft Graph'. Refer to the following URL to access the Microsoft Learning module for hands-on lab exercises and more resources: https://docs.microsoft.com/learn/modules/msgraph-access-user-data
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Microsoft 365 Developer · Microsoft 365 Developer · 0 of 60

← Previous Next →
1 Adaptive Cards community call-February 2019
Adaptive Cards community call-February 2019
Microsoft 365 Developer
2 PowerApps community call-February 2019
PowerApps community call-February 2019
Microsoft 365 Developer
3 Microsoft Graph community call-March 2019
Microsoft Graph community call-March 2019
Microsoft 365 Developer
4 Office Add ins community call-March 2019
Office Add ins community call-March 2019
Microsoft 365 Developer
5 PowerApps community call-March 2019
PowerApps community call-March 2019
Microsoft 365 Developer
6 Microsoft Teams community call-March 2019
Microsoft Teams community call-March 2019
Microsoft 365 Developer
7 Using React and Office UI Fabric React Components
Using React and Office UI Fabric React Components
Microsoft 365 Developer
8 Build Microsoft Teams customization using SharePoint Framework
Build Microsoft Teams customization using SharePoint Framework
Microsoft 365 Developer
9 Microsoft Graph community call-April 2019
Microsoft Graph community call-April 2019
Microsoft 365 Developer
10 Using Change Notifications and Track Changes with Microsoft Graph
Using Change Notifications and Track Changes with Microsoft Graph
Microsoft 365 Developer
11 Office Add Ins community call-April 2019
Office Add Ins community call-April 2019
Microsoft 365 Developer
12 Adaptive Cards community call-April 2019
Adaptive Cards community call-April 2019
Microsoft 365 Developer
13 Microsoft Teams community call-April 2019
Microsoft Teams community call-April 2019
Microsoft 365 Developer
14 Getting Started with Microsoft Graph and Application Registration
Getting Started with Microsoft Graph and Application Registration
Microsoft 365 Developer
15 Getting Started with Microsoft Graph and the Directory API
Getting Started with Microsoft Graph and the Directory API
Microsoft 365 Developer
16 Getting Started with Microsoft Graph and Microsoft Teams
Getting Started with Microsoft Graph and Microsoft Teams
Microsoft 365 Developer
17 Getting Started with Microsoft Graph Explorer
Getting Started with Microsoft Graph Explorer
Microsoft 365 Developer
18 Getting Started with Microsoft Graph
Getting Started with Microsoft Graph
Microsoft 365 Developer
19 Getting Started with Microsoft Graph and Mail API
Getting Started with Microsoft Graph and Mail API
Microsoft 365 Developer
20 Getting Started with Microsoft Graph and Office 365 Groups
Getting Started with Microsoft Graph and Office 365 Groups
Microsoft 365 Developer
21 Getting Started with Microsoft Graph and the Calendar API
Getting Started with Microsoft Graph and the Calendar API
Microsoft 365 Developer
22 Getting Started with the Microsoft Graph Toolkit
Getting Started with the Microsoft Graph Toolkit
Microsoft 365 Developer
23 Getting Started with Microsoft Graph and JavaScript SDKs
Getting Started with Microsoft Graph and JavaScript SDKs
Microsoft 365 Developer
24 Getting Started with Microsoft Graph and .NET SDKs
Getting Started with Microsoft Graph and .NET SDKs
Microsoft 365 Developer
25 Discover how businesses can be more productive with Microsoft 365 integrations
Discover how businesses can be more productive with Microsoft 365 integrations
Microsoft 365 Developer
26 Adaptive Cards community call-May 2019
Adaptive Cards community call-May 2019
Microsoft 365 Developer
27 Office Add-ins community call-May 2019
Office Add-ins community call-May 2019
Microsoft 365 Developer
28 Why We Built on Microsoft Teams
Why We Built on Microsoft Teams
Microsoft 365 Developer
29 Microsoft Teams community call-May 2019
Microsoft Teams community call-May 2019
Microsoft 365 Developer
30 Microsoft Graph community call-June 2019
Microsoft Graph community call-June 2019
Microsoft 365 Developer
31 Build Angular SPA's with Microsoft Graph - June 2019
Build Angular SPA's with Microsoft Graph - June 2019
Microsoft 365 Developer
32 Office Add -ins community call-June 2019
Office Add -ins community call-June 2019
Microsoft 365 Developer
33 Build Android native apps with the Microsoft Graph Android SDK - June 2019
Build Android native apps with the Microsoft Graph Android SDK - June 2019
Microsoft 365 Developer
34 Build MVC apps with Microsoft Graph - June 2019
Build MVC apps with Microsoft Graph - June 2019
Microsoft 365 Developer
35 Authenticate and connect with Microsoft Graph - June 2019
Authenticate and connect with Microsoft Graph - June 2019
Microsoft 365 Developer
36 Microsoft Graph data connect - June 2019
Microsoft Graph data connect - June 2019
Microsoft 365 Developer
37 Change notifications with Microsoft Graph - June 2019
Change notifications with Microsoft Graph - June 2019
Microsoft 365 Developer
38 Build iOS native apps with the Microsoft Graph REST API - June 2019
Build iOS native apps with the Microsoft Graph REST API - June 2019
Microsoft 365 Developer
39 Build Node.js Express apps with Microsoft Graph - June 2019
Build Node.js Express apps with Microsoft Graph - June 2019
Microsoft 365 Developer
40 Smart UI with Microsoft Graph - June 2019
Smart UI with Microsoft Graph - June 2019
Microsoft 365 Developer
41 Leveraging the Microsoft Graph API from the SharePoint Framework - June 2019
Leveraging the Microsoft Graph API from the SharePoint Framework - June 2019
Microsoft 365 Developer
42 Build UWP apps with Microsoft Graph - June 2019
Build UWP apps with Microsoft Graph - June 2019
Microsoft 365 Developer
43 Build React SPA's with Microsoft Graph - June 2019
Build React SPA's with Microsoft Graph - June 2019
Microsoft 365 Developer
44 Getting Started with Microsoft Graph and Batching
Getting Started with Microsoft Graph and Batching
Microsoft 365 Developer
45 Getting Started with Microsoft Graph and Change Notifications
Getting Started with Microsoft Graph and Change Notifications
Microsoft 365 Developer
46 Getting Started with Microsoft Graph and Consent Permissions
Getting Started with Microsoft Graph and Consent Permissions
Microsoft 365 Developer
47 Getting Started with Microsoft Graph and Education
Getting Started with Microsoft Graph and Education
Microsoft 365 Developer
48 Getting Started with Microsoft Graph and Financials
Getting Started with Microsoft Graph and Financials
Microsoft 365 Developer
49 Getting Started with Microsoft Graph and Excel
Getting Started with Microsoft Graph and Excel
Microsoft 365 Developer
50 Getting Started with Microsoft Graph and Data Connect
Getting Started with Microsoft Graph and Data Connect
Microsoft 365 Developer
51 Getting Started with Microsoft Graph and Intune
Getting Started with Microsoft Graph and Intune
Microsoft 365 Developer
52 Getting Started with Microsoft Graph and Notifications
Getting Started with Microsoft Graph and Notifications
Microsoft 365 Developer
53 Getting Started with Microsoft Graph and OneNote
Getting Started with Microsoft Graph and OneNote
Microsoft 365 Developer
54 Getting Started with Microsoft Graph and OneDrive
Getting Started with Microsoft Graph and OneDrive
Microsoft 365 Developer
55 Getting Started with Microsoft Graph and Open Extensions
Getting Started with Microsoft Graph and Open Extensions
Microsoft 365 Developer
56 Getting Started with Microsoft Graph and Paging
Getting Started with Microsoft Graph and Paging
Microsoft 365 Developer
57 Getting Started with Microsoft Graph and Schema Extensions
Getting Started with Microsoft Graph and Schema Extensions
Microsoft 365 Developer
58 Getting Started with Microsoft Graph and Security API
Getting Started with Microsoft Graph and Security API
Microsoft 365 Developer
59 Getting Started with Microsoft Graph and Query Parameters
Getting Started with Microsoft Graph and Query Parameters
Microsoft 365 Developer
60 Getting Started with Microsoft Graph and Reporting API
Getting Started with Microsoft Graph and Reporting API
Microsoft 365 Developer

This video teaches how to use Microsoft Graph to manage users in an organization, including creating, updating, and deleting users, with a focus on modifying an existing Azure AD app and .NET Core console app. The demo shows how to grant the necessary API permissions and make API calls to perform these actions. By following along, viewers can learn how to manage users in their own organization using Microsoft Graph.

Key Takeaways
  1. Grant the user.read.write.all API permission to the Azure AD app
  2. Modify the .NET Core console app to use the Microsoft Graph API
  3. Create a new user using the Microsoft Graph API
  4. Update an existing user using the Microsoft Graph API
  5. Delete a user using the Microsoft Graph API
💡 The Microsoft Graph API provides a powerful way to manage users in an organization, but requires careful configuration of API permissions and authentication.

Related Reads

📰
Why RAM Prices Are Exploding: Inside the DRAM Shortage Fueling the AI Boom
RAM prices are surging due to the DRAM shortage caused by the AI boom, learn how this affects the tech industry and what it means for professionals
Medium · AI
📰
Reflection inks $1B compute deal with Nebius
Learn about Reflection's $1B compute deal with Nebius and its implications for AI and cloud computing
TechCrunch AI
📰
You’ve Been Working for Google for Years — And You Never Got Paid
Discover how your daily interactions with Google have been training their AI without your knowledge or compensation
Medium · AI
📰
You’ve Been Working for Google for Years — And You Never Got Paid
Discover how your everyday interactions with Google may be training their AI without your knowledge or compensation
Medium · Machine Learning
Up next
PLATO Exoplanet Hunter Launch 2026 Searching for New Earths in a Warming World
Tech Folk Insights
Watch →