This question will be a duplicate of this one (which has no accepted answer).
I am trying to save a SP 2013 list item using the REST API.
One of the columns is a People or Group column.
Normally you write to that column by adding "Id" to the column name and using the person/group ID:
MyColumnNameId: 32
However, I do not have the user ID and I only have the login name, e.g. i:0#.w|domain\user
or domain\user
.
How can I write to that column using just the login name and without using the ID?
What I've tried:
- Sending the login name directly
- Trying to get user ID by login first, using this query:
http://domain/sites/mysite/_api/web/siteusers(@v)?@v='" + encodeURIComponent('i:0#.w|domain\user') + "'"
However, this produces an error (and I'm sure the user is there - I got it directly from GetUserById(1):
"{"error":{"code":"-2146232832, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"User cannot be found."}}}"
If I try the same URL without URIencode, it says The query string \"loginName\" is missing or invalid."
.