Getting the SharePoint User Id via Graph API
Problem
If you are wanting to update a Person or Group field in SharePoint Online via the Microsoft Graph API, you need the numerical ID of the User for that Site. This is rather frustrating as:
It doesn't align with the User's Object Id in Entra ID.
You cannot use the Users Object Id to look up the numerical Id in SharePoint Online.
The numerical Id in SharePoint Online is not guaranteed to be the same across multiple SIte Collections.
Resolution
Within each Site, there is a hidden List called User Information List. This can be retrieved by using the Graph API and querying the following URL:
https://graph.microsoft.com/beta/sites/root/lists?$filter=DisplayName+eq+'User+Information+List'
Find the ID out of this response and replace {list_id}in the URL below to get the list of Users:
https://graph.microsoft.com/beta/sites/root/lists/{list_id}/items
We run into an issue here, however. As of January 2025, using OData filters to try to do the searching on the Graph API side returns an Internal Server Error with the message General exception while processing.
Once you have this list in full (you may need to paginate through a few pages depending on the user count of the tenant), you can then filter based on Email Address (recommended) or Display Name (not recommended).
Closing
I haven't found a Graph API Endpoint that I can use to easily convert an Entra ID Object Id to the numerical Id of a SharePoint Site.
The only workaround I've found is to bring the whole list in and then use a filter or lookup to get the information I am looking for.
Last updated