Graph API - Create ListItem with User Column

Shadi Rashed 71 Reputation points
2022-06-16T10:32:52.67+00:00

Hello,
I am trying to create a new ListItem through the Graph REST API. The list has a user column. I want to create a new item in the list and fill it with a user automatically. I have the email of the user.
Is that possible or do I first need to get the user id?

I should mention that I already know how to create the list item through the API and that I know in general how to fill fields and also more complex fields like multi selects. I just wonder what the correct structure is for setting the user field

Thanks for your help!
Shadi

Microsoft 365 and Office SharePoint Development
Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2022-06-17T02:55:15.593+00:00

    Hi anonymous userRashed-1057 ,
    You can update single value 'personOrGroup' fields, by combining the field name with LookupId and passing the LookupId as the value:

    {  
       "AssignedToLookupId":"123"  
    }  
    

    If you want to update a multi value 'personOrGroup' fields, you need to specify the data type first and pass the ids as an array:

    {  
       "******@odata.type":"Collection(Edm.String)",  
       "AssignedToLookupId":["123", "124"]   
    }  
    

    Here is a similar issue with yours for reference
    https://stackoverflow.com/questions/47010078/how-to-update-a-lookup-field-and-a-user-field-in-sharepoint-with-microsoft-graph


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



  2. Shadi Rashed 71 Reputation points
    2022-06-17T08:58:47.82+00:00

    OK I found out how to do this. Its much more complicated than should be necessary. For assigning the User you cant simply use the user id or the email address. Instead Sharepoint maintains a separate hidden user list with lookup ids. Follow these steps

    1. execute the below request. It will give you some Sharepoint lists. Find the list with name “Users” or something similar
      GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists?$select=system,name,id
    2. Query the list items of that list. If you want to filter by email address, the request would look like
      https://graph.microsoft.com/v1.0/sites/<siteid>/lists/<listid>/items?$filter=fields/EMail?$filter=fields/EMail eq '<email address>'&$select=id

    this will give you the lookup id which you can then use as described above


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.