Question

I am trying to set value in people picker field. I want to pass an Email address of the employee instead of employee ID in the API.

Any help is highly appreciated.

Using API endpoint: _api/web/lists/getbytitle('list name')/items

Body :
{
    "Title" : "title",
    "Owner/EMail" : "sample@sample.com"
}

But this is not working instead if I use the given below body it will work:

{
    Body :
    {
        "Title" : "title",
        "OwnerID" : 65
        "OwnerStringID" : "65"
    }
}
Was it helpful?

Solution

This is the expected behavior while using SharePoint REST API. To set the people picker fields or lookup fields we need to pass the corresponding ID.

If you have an email address of user you can get its User ID using below endpoint:

<site url>/_api/web/siteusers?$select=Id&$filter=Email eq '<user email address>'

If you want to get the user ID of currently logged in user then you directly use:

var userId = _spPageContextInfo.userId;
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top