I am trying to create a SharePoint list item via the Graph API which includes a people picker field as well as several others. I am using an HTTP POST request to pass a JSON payload to the correct endpoint located at https://graph.microsoft.com/v1.0/sites/{my_site_id}/lists/{my_list_id}/items. The list item has a "Tested By" field which is the people picker.
The creation completes just fine, so long as I leave this "Tested By" field blank, but for my use case, this field needs to be populated for audit compliance. Under the hood, if you GET an existing list item, the field shows up with the title "Tested_x0020_By," which exists as:
"Tested_x0020_By": [{
"LookupId": 123,
"LookupValue": "John Doe",
"Email": "John.Doe@mycompany.com"
}]
But when you try to POST a JSON payload which includes this field using a patch document which matches this exact format, it blows up with an HTTP 400 "Invalid Request." No further information to be had other than "Invalid Request" to say why it is, in fact, invalid. I've tried passing the full three items as well as only the LookupId.
How am I supposed to create a list item which includes data for this field?
HTTP POST request to https://graph.microsoft.com/v1.0/sites/{my_site_id}/lists/{my_list_id}/items with a JSON payload including the field listed above. Expected to receive an HTTP 2XX response with the typical information from Microsoft Graph showing item creation. Did receive an HTTP 400 "Invalid Request" with no further amplifying info about what, in fact, was invalid. Request will complete successfully when not including the "Tested_x0020_By" field in the JSON payload.
I think there is a workaround for this
Add LookupId
to the name of the people picker column and specifies only lookup ids in the array
POST https://graph.microsoft.com/v1.0/sites/{site_id}/lists/{list_id}/items
{
"fields": {
"Tested_x0020_ByLookupId@odata.type": "Collection(Edm.Int32)",
"Tested_x0020_ByLookupId": [123]
}
}
You need to specify the type of the field to make sure OData understands it by adding "Tested_x0020_ByLookupId@odata.type": "Collection(Edm.Int32)"