I have a list of email adresses that needed to be added to a list using script. How can I resolve the email address to its ID, or set the User field directly with the email address?
This is my code (not working of course)
$(function (){
var link = _spPageContextInfo.webAbsoluteUrl+"/_api/web/lists/GetByTitle('Names')/items('2')";
var email = "[email protected]"
var data = JSON.stringify({ '__metadata': { 'type': 'SP.Data.NamesListItem' }, 'User': 'i:0#.f|membership|'+email});
PostData(link, data);
function PostData(url, data){
return $.ajax({
url: url,
method: "POST",
data: data,
headers:
{
"accept": "application/json;odata=verbose",
"content-type":"application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"X-HTTP-Method": "MERGE",
"If-Match": "*"
},
});
}
});