Share via

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

Anonymous
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

Microsoft 365 and Office | SharePoint | Development

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,496 Reputation points Microsoft External Staff
    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.

    Was this answer helpful?


Your answer

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