Get Multiple Lookup field for a ListItem in Microsoft Graph API

Anonymous
2021-06-02T16:48:52.467+00:00

I have a lookup column in Sharepoint Online that allows multiple values per item. I use the Microsoft Graph .NET SDK to retrieve all the column values for a list item:

ListItem item = await graphClient.Sites[siteId].Drive.Items[itemId].ListItem.Fields.Request().GetAsync();

I also tried to retrieve the multiple lookup column specifically:

var queryOptions = new List<QueryOption>()
{
   new QueryOption("expand", "fields(select=MultipleLookupColumn)"))
};
ListItem item = await graphClient.Sites[siteId].Drive.Items[itemId].ListItem.Request(queryOptions).GetAsync();

It correctly shows the column values, including custom columns, except for the multiple lookup column. The lookup column shows up in item.Fields.AdditionalData, but it is always an empty array, even when there are values assigned to it on Sharepoint Online. But if I change the lookup column to disallow multiple values, it shows the value correctly.

So I tried to send an HTTP GET request to see if it is an issue with the SDK. Unfortunately, the resulting JSON also shows an empty array, which means that it is an issue with the Graph API itself. For example, with the column MultiLookup:

"fields": {
                "@odata.etag": "\"acf66f85-cc5e-4dcf-a276-e4e5edf5e758,21\"",
                "FileLeafRef": "file.pdf",
                "MultiLookup": [],
                "MultiLookup_x003a_Created": [],
                "id": "31",
                "ContentType": "Document",
                "Created": "2021-05-31T19:43:03Z",
                "AuthorLookupId": "10",
                "Modified": "2021-06-02T13:06:52Z",
                "EditorLookupId": "12",
                "_CheckinComment": "",
                "LinkFilenameNoMenu": "file.pdf",
                "LinkFilename": "file.pdf",
                "DocIcon": "pdf",
                "FileSizeDisplay": "31151",
                "ItemChildCount": "0",
                "FolderChildCount": "0",
                "_ComplianceFlags": "",
                "_ComplianceTag": "",
                "_ComplianceTagWrittenTime": "",
                "_ComplianceTagUserId": "",
                "_CommentCount": "",
                "_LikeCount": "",
                "_DisplayName": "",
                "AppAuthorLookupId": "12",
                "Edit": "0",
                "_UIVersionString": "21.0",
                "ParentVersionStringLookupId": "31",
                "ParentLeafNameLookupId": "31"
            }

To make sure that it is a bug specific to the Graph API, I also tried getting the lookup values from the old Sharepoint REST API:

https://{site_url}/_api/Web/Lists(guid'{guid_id}')/Items({item_id})

With the old Sharepoint REST API, I was able to get the lookup values, although the column is called MultiLookupId instead of MultiLookup.

<d:MultiLookupId m:type="Collection(Edm.Int32)"><d:element>5</d:element><d:element>10</d:element><d:element>11</d:element></d:MultiLookupId>

Unfortunately, the old REST API only works on my browser when I am signed in. When I tried to call the old API programmatically with the same access token that I use for Microsoft Graph API, I get an Unauthorized (401) error.

At this point, I am fairly certain that this is a bug in the Microsoft Graph API. Is this an easy fix for the Microsoft dev team, or there another way I can retrieve the multi-lookup column values?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,646 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,682 questions
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2021-06-03T12:46:03.227+00:00

    Hi @MichaelHan-MSFT , thanks for your attempt.

    I found that it is a permissions issue. I had set up my app with the Files.ReadWrite.All permission, which is sufficient for reading the document library and files in Sharepoint Online, including lookup columns with single values. But unfortunately not lookup columns with multiple values. Once I added Sites.Read.All to permissions, the multiple lookup values array was no longer empty. I believe this is undocumented.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. MichaelHan-MSFT 18,016 Reputation points
    2021-06-03T03:00:15.74+00:00

    Hi @Anonymous ,

    Per my test, I could get the Multiple Lookup field for a ListItem on my end. Below is my test result:

            var fieldValueSet = await graphClient.Sites[siteID].Drive.Items[itemID].ListItem.Fields  
                                 .Request()  
                                 .GetAsync();  
            var value=new Object();  
            if (fieldValueSet.AdditionalData.TryGetValue("MultiLookup", out value))  
            {  
                Console.WriteLine(value);  
            }  
    

    101931-image.png

    101941-image.png

    And in Graph Explorer:

    101790-image.png

    Besides, we could use this endpoint to get the list item directly: https://learn.microsoft.com/en-us/graph/api/listitem-get?view=graph-rest-1.0&tabs=csharp

    0 comments No comments