How to use contains string in filter criteria in microsoft graph api?

Pradhaan, Surrya 0 Reputation points
2024-05-09T09:45:05.54+00:00

I am using graph api to search product list from sharepoint.

I am able to search product using startsWith function but my requirement is to search product using any keyword which contains product name.

I am currently using below url statsWith function to search product.

https://graph.microsoft.com/v1.0/sites/{siteId}/lists/{listId}/items?select=fields&expand=fields(select=Title,Product_Description,Product_x0020_Portfolio,Product_Manager_txt)&$filter=startsWith(fields/Title,'Auto')

but i need to search product any keyword from the product name .

When i use key word contains it throws error contains key

https://graph.microsoft.com/v1.0/sites/{siteId}/lists/{listId}/items?select=fields&expand=fields(select=Title,Product_Description,Product_x0020_Portfolio,Product_Manager_txt)&$filter=contains(fields/Title,'Auto')

response:

{

    "error": {

        "code": "itemNotFound",

        "message": "Item not found",

        "innerError": {

            "date": "2024-05-08T20:26:09",

            "request-id": "2fc2e894-9435-4320-a036-c53ab4ff4f4b",

            "client-request-id": "c7892a64-3dc8-e409-8292-abbe0c38fce1"

        }

    }

}

Please Help me to solve my issue and fulfill my requirement

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,726 questions
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 32,246 Reputation points Microsoft Vendor
    2024-05-10T02:22:54.8266667+00:00

    Hi @Pradhaan, Surrya

    Per my research, list item doesn't support contains. You could refer to following issue similar with yours

    [https://learn.microsoft.com/en-us/answers/questions/1016924/graph-api-sharepoint-list-search-(contains-startsw](https://learn.microsoft.com/en-us/answers/questions/1016924/graph-api-sharepoint-list-search-(contains-startsw)

    As a workaround, you could use rest api to Realize the contain function. Please refer to following api

     /_api/web/lists/getByTitle('Address')/items?$select=Title,Id,Company,City&$filter=substringof('e',Company)
    
    

    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.