I have set up a React web app consuming data using Microsoft Graph from SharePoint Online which is working well. I can read and write to SP Lists, but I am unable to find any documentation regarding how to structure the data to write into a 'People/Group' field.
Querying a list with these fields yields "ManagerLookupId": "12"
, where Manager
is the People Picker field name. I can resolve the "12"
by using the expand query string. I can't figure out how to write to it using either the /v1.0
or /beta
endpoints from Microsoft Graph
Posting this object to the relevant endpoint works (for Single Line Text, Choice, etc).
{
"fields": {
"Title": "a",
"Category": "b",
"Description": "c"
}
}
But if I were to add in the People picker field, I don't know how to structure that data. I have tried email address and GUID, both of which didn't work. Looking at how SP does it natively, it appears to submit this value on submission for the people picker field (have replaced real values) -
{
"Key": "i:0#.f|membership|EMAIL",
"DisplayText": "NAME",
"IsResolved": true,
"Description": "EMAIL",
"EntityType": "User",
"EntityData": {
"IsAltSecIdPresent": "False",
"Title": "POSITION",
"Email": "EMAIL",
"MobilePhone": "",
"ObjectId": "GUID",
"Department": ""
},
"MultipleMatches": [],
"ProviderName": "Tenant",
"ProviderDisplayName": "Tenant"
}
Replicating this also fails to update the People field in the list.
I wasn't able to find any documentation on the MS Graph API site or similar previous questions on their Github, so any help would be really appreciated!
I have set up a React web app consuming data using Microsoft Graph from SharePoint Online which is working well. I can read and write to SP Lists, but I am unable to find any documentation regarding how to structure the data to write into a 'People/Group' field.
Querying a list with these fields yields "ManagerLookupId": "12"
, where Manager
is the People Picker field name. I can resolve the "12"
by using the expand query string. I can't figure out how to write to it using either the /v1.0
or /beta
endpoints from Microsoft Graph
Posting this object to the relevant endpoint works (for Single Line Text, Choice, etc).
{
"fields": {
"Title": "a",
"Category": "b",
"Description": "c"
}
}
But if I were to add in the People picker field, I don't know how to structure that data. I have tried email address and GUID, both of which didn't work. Looking at how SP does it natively, it appears to submit this value on submission for the people picker field (have replaced real values) -
{
"Key": "i:0#.f|membership|EMAIL",
"DisplayText": "NAME",
"IsResolved": true,
"Description": "EMAIL",
"EntityType": "User",
"EntityData": {
"IsAltSecIdPresent": "False",
"Title": "POSITION",
"Email": "EMAIL",
"MobilePhone": "",
"ObjectId": "GUID",
"Department": ""
},
"MultipleMatches": [],
"ProviderName": "Tenant",
"ProviderDisplayName": "Tenant"
}
Replicating this also fails to update the People field in the list.
I wasn't able to find any documentation on the MS Graph API site or similar previous questions on their Github, so any help would be really appreciated!
Share Improve this question edited Jun 3, 2019 at 16:36 Marc LaFleur 33.2k4 gold badges40 silver badges70 bronze badges asked Jun 2, 2019 at 13:24 RonaldRonald 331 silver badge4 bronze badges2 Answers
Reset to default 7You can find some information about this in the documentation for FieldValueSet
:
Lookup fields (like
Author
above) are not returned by default. Instead, the server returns a 'LookupId' field (likeAuthorLookupId
above) referencing thelistItem
targeted in the lookup. The name of the 'LookupId' field is the original field name followed by LookupId.
Under the covers, this is a side-effect of how SharePoint tracks users. As an artifact of history, SharePoint maintains it's own User database. While there was a point in time when SP Admins had a lot of exposure to these users, today it's a fully automated process. It simply creates a new SPUser
record the first time it sees an authenticated AAD User. These User records have their own id
property. This is a mon INT
rather than a GUID
(in your example, their id
is 12
).
When you're updating a ListItem
, you need to use SharePoint's id
. You can pass this as a single value or as an array:
{
"fields": {
"ManagerLookupId": 12
}
}
{
"fields": {
"ManagerLookupId": [10,11,12]
}
}
Here is the rub, there is no way to obtain this SharePoint User id
from Microsoft Graph. Obviously, this makes it really challenging to create/update a ListItem
. To get around this, you can use the old SharePoint REST API's ensureUser
endpoint:
http://<sitecollection>/<site>/_api/web/ensureUser(logonName)
Keep in mind, you'll also need a token for SharePoint to call this API. If you're using the AAD v1 Endpoint, this is generally just a matter of refreshing your token using your SharePoint resource (https://{tenant}.sharepoint.
) for this call and then refreshing back to the Graph resource (https://graph.microsoft.
) for your other calls.
My test demo, User is people field allow multiple users.
{
"fields": {
"Title": "test",
"[email protected]": "Collection(Edm.Int32)",
"UserLookupId":[10,23]
}
}
For one user.
{
"fields": {
"Title": "test",
"[email protected]": "Edm.Int32",
"UserLookupId":23
}
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744978804a4604311.html
评论列表(0条)