Return custom column with Graph API search of SharePoint List

Rebecca Dorman 20 Reputation points
2023-08-28T06:37:51.8033333+00:00

I am currently attempting to search a SharePoint list using the Graph Search API (aka this endpoint: https://graph.microsoft.com/v1.0/search/query). Note that I am still a novice in regards to the Graph API so please bear with me.

I have a column in a list in my site called ItemCategory that I am wanting to return as part of my search results. I have mapped the crawled property for this column to a Managed Property, also called ItemCategory in the search schema and have confirmed that I can return results from this Managed property using the SharePoint REST API. However this has limitations that I am trying to avoid by using the Graph API.

My request body looks like the following:

{
     "requests": [
         {
             "entityTypes": [
                 "listItem"
             ],
             "query": 
			 {
                 "queryString": " SearchText  path: \"https://mytenant.sharepoint.com/sites/mysitename/mylistname\""
             },
             "fields": [
                 "title",
                 "ItemCategory",
                 "path",
                 "fileName",
             ]
         }
     ] 
}

While this does return results, and does include the title, path and filename, the ItemCategory is simply ignored. I should mention that the ItemCategory contains one or more category names as text.

Is there something I am missing, or is this simply not possible? Thanks in advance

Microsoft 365 and Office SharePoint For business Windows
Microsoft Security Microsoft Graph
{count} vote

3 answers

Sort by: Most helpful
  1. Rebecca Dorman 20 Reputation points
    2023-09-14T06:24:29.6533333+00:00

    For anyone looking for the solution to this issue, I have found that the issue was that I used a Site level managed property instead of a tenant level managed property. Apparently the Graph API cannot search/return Site level managed properties.

    2 people found this answer helpful.

  2. Rebecca Dorman 20 Reputation points
    2023-08-31T04:55:02.9233333+00:00

    Thank you for your response Cheng. Unfortunately this did not resolve the issue and in fact did not appear to be recognised at all given that none of the properties listed in the expand property of your suggested request body were returned.

    According to this page: https://learn.microsoft.com/en-us/graph/search-concept-files

    it should work with the Fields property as per the following statement under Example 6: "Note that property selection for custom properties in SharePoint is only available for listItem or driveItem because these are the only two SharePoint entities in Microsoft Graph that support custom properties."

    Also, if this statement from your response was correct: "However, not all fields are available for all entity types. For list items, only the following fields are supported:

    id

    name

    webUrl

    createdDateTime

    lastModifiedDateTime

    createdBy

    lastModifiedBy

    parentReference

    sharepointIds", how is it that using the fields property in my response body that I am able to return the Title, Path and filename, as none of these are in that list of supported properties?

    And I can't find reference in the Microsoft Learn site to the syntax you suggested Cheng. Are you able to provide a documentation reference for this at all?

    Does anyone have any other suggestions?

    1 person found this answer helpful.

  3. Anonymous
    2023-08-29T07:46:29.91+00:00

    Hi @Rebecca Dorman

    The fields property in the search request specifies the fields to be returned in the search response.

    However, not all fields are available for all entity types. For list items, only the following fields are supported:

    id

    name

    webUrl

    createdDateTime

    lastModifiedDateTime

    createdBy

    lastModifiedBy

    parentReference

    sharepointIds

    Therefore, if you want to get the value of a custom column (such as ItemCategory) for list items, you cannot use the fields property in the search request.

    Instead, you need to use the expand property to expand the fields facet of the list item resource.

    For example, your request body should look like this:

    {
         "requests": [
             {
                 "entityTypes": [
                     "listItem"
                 ],
                 "query": 
    			 {
                     "queryString": " SearchText  path: \"https://mytenant.sharepoint.com/sites/mysitename/mylistname\""
                 },
                 "expand": [
                     "fields(select=ItemCategory,title,path,fileName)"
                     
                 ]
             }
         ] 
    }
    
    

    This will return the value of the ItemCategory column in the fields facet of the list item resource in the search response.

    You can also specify multiple columns to expand by separating them with commas, such as "fields(select=ItemCategory,Priority)".

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


    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


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.