Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graph API search with special character in $filter

Below is the code. If I pass search value of search parameter e.g: M'test. It throws error.

What is the right way to use this code to support special character like "'"?

var graphClient = await GetGraphClient();
List<QueryOption> queryOptions = new List<QueryOption>();
queryOptions.Add(new QueryOption("$filter", string.Format("startswith(displayName,'{0}')", search)));
var collection = await graphClient.Data.Request(queryOptions).GetAsync();
like image 675
manish raghu Avatar asked Sep 05 '25 16:09

manish raghu


1 Answers

Escaping single quotes

For requests that use single quotes, if any parameter values also contain single quotes, those must be double escaped; otherwise, the request will fail due to invalid syntax.

In your example, M'test would need to be M''test.

You could likely just use string.Replace or regex to replace ' with ''

like image 191
TheGeneral Avatar answered Sep 07 '25 09:09

TheGeneral