When we want to use MS Graph to add an item into a SharePoint List that contains a People Picker, then here what needs to be done:
- Retrieve the Site ID for the root site collection, using
https://graph.microsoft.com/v1.0/sites/[CORP].sharepoint.com:/sites/MySiteCollection - Retrieve the Site ID for the target end website, using
https://graph.microsoft.com/v1.0/sites/[CORP].sharepoint.com:/sites/MySiteCollection/MyParentSiteWeb/MyTargetWebsite/ - Use the user’s email address to retrieve the SharePoint User ID of that person from the User Information List, using
https://graph.microsoft.com/v1.0/sites/[ROOT_SITE_ID]/lists/User%20Information%20List/items?expand=fields&filter=fields/EMail%20eq%20'[ENCODED_EMAIL]'&top=1"– the email must be encoded to be passed in an URL - If the user doesn’t exist in this SharePoint yet, then you have to use the REST API call to
https://[CORP].sharepoint.com/sites/MySiteCollection/MyParentSiteWeb/MyTargetWebsite/_api/web/ensureUserwith the payload{"logonName":"user_email@corp.com"}– you should get the User ID this time - Then we need to get the List ID of where we want to add the item, using
https://graph.microsoft.com/v1.0/sites/[TARGET_SIDE_ID]/lists/[LIST_NAME_ENCODED] - Finally, we can add the item using
https://graph.microsoft.com/v1.0/sites/[TARGET_SIDE_ID]/lists/[TARGET_LIST_ID]/itemswith a specific value depending if it’s a multi-selection people picker field or not – let’s say the internal name for my field is “Requestor_x0020_Name”, then I have to append “LookupId” to this name:- for a single selection field, the payload contains:
{"Requestor_x0020_NameLookupId": "[USER_ID_FOUND_WITH_GRAPH]"} - for a multi-selection field we have to pass the odata type, and put the User ID into an array, then the payload contains:
{ "Requestor_x0020_NamesLookupId@odata.type":"Collection(Edm.String)", "Requestor_x0020_NamesLookupId": [ "[USER_ID_FOUND_WITH_GRAPH]" ] }
- for a single selection field, the payload contains: