how to get the microsoft graph api latest updated user group changes to identify modified user.

Anand Mallela 0 Reputation points
2024-06-03T09:47:24.59+00:00

unable to get the modified information for particular user in groups if there is any update happens for a single user in graph api for azure active directory.

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,939 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,382 questions
Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,211 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. William 620 Reputation points
    2024-06-03T11:42:24.4366667+00:00

    To retrieve recently modified or added users from Azure Active Directory using the Graph API, you have a couple of options:

    Option 1: Delta Queries

    Delta queries allow you to track changes in your directory. You can use the user-delta endpoint to get a list of users that have been modified or added since the last query.

    Here’s an example of how to use delta queries to fetch users in C#:

    csharpCopy code
    var
    

    Make sure to handle the nextLink or deltaLink in the response to retrieve subsequent pages of results.

    Option 2: Owned Objects

    If you’re interested in groups that a specific user owns, you can use the ownedObjects endpoint. This will give you a list of directory objects (including groups) owned by the user.

    The request would look like this:

    httpCopy code
    GET https://graph.microsoft.com/v1.0/users/{user-id}/ownedObjects
    

    You can then filter the results to get the group names and types.

    Detailed Steps for Delta Queries

    Initialize Delta Query:

    • Make a request to the users/delta endpoint to get the initial set of users and a @odata.deltaLink to track changes.

    Process Initial Response:

      - The initial response will include the current state of users and a **`@odata.deltaLink`**.
      
      **Track Changes Using Delta Link:**
      
         - Use the **`@odata.deltaLink`** to periodically check for updates since the last query.
         
    

    Example for Delta Queries in Python

    Here’s how you can implement delta queries using Python and the requests library:

    pythonCopy code
    import
    

    Handling Pagination

    When making delta queries, handle pagination using @odata.nextLink for multiple pages of results:

    csharpCopy code
    while
    

    By using delta queries and owned objects endpoints, you can efficiently track and retrieve modified or added users and their related groups in Azure Active Directory.

    I

    0 comments No comments

  2. Saranya Madhu-MSFT 455 Reputation points Microsoft Vendor
    2024-06-03T15:23:09.96+00:00

    Hi @Anand Mallela ,

    Thanks for reaching out!

    I understand that you are trying to get updates on users in groups using Graph API.

    As per the document to get newly created, updated, or deleted groups, including group membership changes, without having to perform a full read of the entire group collection, you can use delta query on groups

    GET https://graph.microsoft.com/v1.0/groups/delta

    You can use $select=members to get membership changes. You can additionally track other changes like ownership and more by selecting any group relationship of type directoryObject collection.

    Refer here to track changes on group with delta function.

    You can also subscribe to change notifications which enable applications to receive alerts when a Microsoft Graph resource they're interested in changes; that is, created, updated, or deleted. The Microsoft Graph REST API can deliver change notifications to clients through various endpoints, including webhooks, Event Hubs, and Event Grid.

    User's image

    Document reference: https://video2.skills-academy.com/en-us/graph/api/subscription-post-subscriptions?view=graph-rest-1.0&tabs=http

    Hope this helps.

    If the reply is helpful, please click "Accept Answer" and kindly upvote it. If you have additional questions about this answer, please click "Comment".

    0 comments No comments