SPUser field is returning only ID in REST
Domanda
I have my multi-value SPUser field in my list. When accessing it via REST, I am only able to retrieve the ID of the SPUsers. In the result of the REST, the SPUser field was also appended by an Id in the column name. I would need to retrieve the Names of the user, what would be the easiest and most practical way to do it?
Soluzione
It is the way SharePoint works. For lookup column it returns the Id only. If you need more information from lookup column, then just use $expand
in your query. For example
/_api/Web/Lists/GetByTitle('SpTutorial')/Items?$select=SPUser/Title&$expand=SPUser
Result without $expand
"SpUsersId": {
"__metadata": {
"type": "Collection(Edm.Int32)"
},
"results": [
33,
22
]
}
Result with $expand
"SpUsers": {
"results": [
{
"__metadata": {
"id": "e9a1d4f9-5d6d-4a4c-8753-ce1b5020b125",
"type": "SP.Data.UserInfoItem"
},
"Title": "Mohammad Mazumder"
},
{
"__metadata": {
"id": "6d968e6a-830a-4997-bba3-035dc1acdc85",
"type": "SP.Data.UserInfoItem"
},
"Title": "Admin"
}
]
}
Check more about REST API in my article.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange