1

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"
    }
}
  • 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. – Ganesh Sanap Jun 26 at 0:45
  • Thank you for your response Ganesh. But how can I retrieve the ID from SharePoint? – Akansha Sharma Jun 26 at 11:00
  • You can use REST API to get the user ID from SharePoint using email address OR if you want to get the user ID currently logged in user you can directly get it from _spPageContextInfo. Check my answer below. – Ganesh Sanap Jun 26 at 11:13
0

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;
| improve this answer | |
  • I don't know where I am missing but I tried the above API and I could see that the user ID is changing based on the list in SharePoint. So if the employee email is already present in the list then the above API is working but I need to add Employee email in an empty list. – Akansha Sharma Jun 30 at 13:55
  • This endpoint does not fetch the user ID form any custom SharePoint list. It is getting a user ID from SharePoint site context by passing an email address. – Ganesh Sanap Jun 30 at 15:53
  • Then do we have any API / way using which I can add value in people picker field in custom SharePoint list? – Akansha Sharma Jul 1 at 4:00
  • I think you didn't get what I am trying to explain. First of all, you will need an ID of user to add him/her in people picker field in list. And you don't know the user ID, but you do know an email address. So, First you need to get the user ID by passing an email address to <site url>/_api/web/siteusers?$select=Id&$filter=Email eq '<user email address>'. Using this endpoint you will get an user ID in success function of the first REST API. Then in this success function, you will call second REST API: _api/web/lists/getbytitle('list name')/items and pass the user ID you got to Body. – Ganesh Sanap Jul 1 at 4:22
  • @AkanshaSharma, have you resolved this issue? – Ganesh Sanap 12 hours ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.