Cannot create SharePoint list item which includes people picker value

Chris Warrick 0 Reputation points
2023-08-18T18:21:56.0066667+00:00

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": "******@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? "Invalid Request" is an insufficient amount of information for me to figure out what I am doing wrong and fix it.

Microsoft 365 and Office SharePoint Development
Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Anonymous
    2023-08-21T02:18:06.75+00:00

    Hi @Chris Warrick

    Here is a link for your reference:

    https://learn.microsoft.com/en-us/answers/questions/891840/graph-api-create-listitem-with-user-column

    I hope this helps you solve your problem. If you have any other questions, please feel free to ask.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards

    Cheng Feng

    0 comments No comments

  2. Chris Warrick 0 Reputation points
    2023-08-21T15:32:46.4266667+00:00

    For anyone reading down the road, I found a solution via a helpful individual on StackOverflow. It's very close to Cheng Feng's post above, but the linked doc recommends passing the LookupId as a Collection(Edm.String). The correct answer was to pass it as a Collection(Edm.Int32). Correct JSON is:

    {
        "fields": {
            "******@odata.type": "Collection(Edm.Int32)",
            "Tested_x0020_ByLookupId": [123]
        }
    }
    
    0 comments No comments

  3. Anonymous
    2023-08-22T05:20:43.9933333+00:00

    Hi @Chris Warrick

    I'm glad to hear you solve the problem ,if you have any issue about SharePoint, you are welcome to raise a ticket in this forum.

    By the way, since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others." and according to the scenario introduced here: Answering your own questions on Microsoft Q&A, I would make a brief summary of this thread:

    [Cannot create SharePoint list item which includes people picker value]

    Issue Symptom:

    "Tested_x0020_By": [{
                "LookupId": 123,
                "LookupValue": "John Doe",
                "Email": "******@mycompany.com"
            }]
    
    

    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.

    Solution:

    {
        "fields": {
            "******@odata.type": "Collection(Edm.Int32)",
            "Tested_x0020_ByLookupId": [123]
        }
    }
    

    You could click the "Accept Answer" button for this summary to close this thread, and this can make it easier for other community member's to see the useful information when reading this thread. Thanks for your understanding!


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards

    Cheng Feng

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.