Adding Items in Sharepoint list with PersonOrGroup Column

Moustafa El-Sawy 25 Reputation points
2024-06-18T23:53:13.51+00:00

I have a sharepoint site with 1k+ members. This is a public group/site within our tenant. Within that site I have a list where I am collecting feedback. The list has several columns, 2 of which are of type PersonOrGroup (one allows for multi-selection, the other doesnt).

On a desktop c# application I am trying to populate items in this list and I am able to add items in regular columns but I am struggling to make it work for the PersonOrGroup columns. I am using MSFT Graph API with the proper permissions. From what I gathered online these columns hold lookupIDs of users not an actual user. This lookupID corresponds to an internal "hidden" User Information List within the site that contains all the users and their corresponding ID.

Based on this, I was able to find this list and its listID. When I read this list, I do not find all the user members in the group? An example of the items I get when I look at this list is below:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites('xxx')/lists('xxxx')/items",
    "@odata.nextLink": "https://graph.microsoft.com/v1.0/sites/xxx/lists/xxxx/items?$skiptoken=UGFnZWQ9VFJVRSZwX0lEPTIwMw",
    "@microsoft.graph.tips": "Use $select to choose only the properties your app needs, as this can lead to performance improvements. For example: GET sites('<key>')/lists('<guid>')/items?$select=contentType,sharepointIds",
    "value": [
        {
            "@odata.etag": "\"73020bf1-00c2-43ce-8f35-ca76febdde60,9\"",
            "createdDateTime": "2020-07-12T05:50:47Z",
            "eTag": "\"73020bf1-00c2-43ce-8f35-ca76febdde60,9\"",
            "id": "3",
            "lastModifiedDateTime": "2023-02-03T17:55:43Z",
            "webUrl": "https://xxx/sites/xxx/_catalogs/users/3_.000",
            "createdBy": {
                "user": {
                    "displayName": "System Account"
                }
            },
            "lastModifiedBy": {
                "user": {
                    "displayName": "System Account"
                }
            },
            "parentReference": {
                "id": "xxx",
                "siteId": "xxx"
            },
            "contentType": {
                "id": "0x010B00632ECBA8D44FE94497E4391263B20146",
                "name": "SharePointGroup"
            }
        },
        {
            "@odata.etag": "\"664b3e21-e378-42ce-aaae-e517eab3e4e0,22\"",
            "createdDateTime": "2020-08-24T01:23:13Z",
            "eTag": "\"664b3e21-e378-42ce-aaae-e517eab3e4e0,22\"",
            "id": "18",
            "lastModifiedDateTime": "2023-10-03T07:08:57Z",
            "webUrl": "https://xxx/sites/xx/_catalogs/users/18_.000",
            "createdBy": {
                "user": {
                    "email": "xxx@xx.com",
                    "id": "f56f4408-6137-48e1-8f19-3b371f5991d1",
                    "displayName": "xx, xx"
                }
            },
            "lastModifiedBy": {
                "user": {
                    "displayName": "System Account"
                }
            },
            "parentReference": {
                "id": "aca980ac-e2d5-4e7c-be3f-529cb63f4e91",
                "siteId": "xx"
            },
            "contentType": {
                "id": "0x010A00E90A5A3773F58C45B64E73AA5366410D",
                "name": "Person"
            }
        },..      

Based on the data above, I would loop through the items and check when the contentType -> name = Person, then look at createdBy -> user -> email and check if this is the email of the user I am looking for. However I am noticing that not all users are in this list (I cant even find myself). It is not an issue with pagination, I am going through all the data and request urls.

So based on all of this, how am I able to add users to the PersonOrGroup column based on their email?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,094 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,041 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,500 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 32,646 Reputation points Microsoft Vendor
    2024-06-19T02:16:23.7633333+00:00

    Hi @Moustafa El-Sawy,

    Per my research, we need to use lookupid to update user column. This will need the user exist in the site user information list. Then you can use following api to update user column

    Url: https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items/{item-id}/fields    
    Method: PATCH 
    Body: {
      "{columnname}LookupId": "{userid}"
    }
    
    
    

    Here is a similar issue with yours

    https://stackoverflow.com/questions/42701107/how-do-i-update-the-value-of-person-or-group-columns-in-sharepoint-lists-using-t


    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.