How do you escape the octothorpe (number/pound/hashtag symbol) in a Graph API OData search string?

Barry Hagan 21 Reputation points
2021-06-11T16:42:51.387+00:00

When attempting to search groups in the Graph API using the literal # symbol, the API returns an error even when URI encoding the search string.

For example:

https://graph.microsoft.com/v1.0/groups?$select=id,displayName,description&$search="displayName:%23"

(with the ConsistencyLevel:eventual header)

Graph API returns this error:

 {
     "error": {
         "code": "Request_UnsupportedQuery",
         "message": "Syntax error in $search. A right $search should be $search=\"property:textToSearch\" [OR|AND \"anotherProperty:text\"].",
     }
 }

I've tried various other quoting or escaping techniques with no success. Is there a right search when using this character?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,582 questions
0 comments No comments
{count} votes

Accepted answer
  1. Oleksandr Yevchenko 81 Reputation points
    2021-08-13T09:59:14.337+00:00

    Hi,
    I use #2523 for the # sign as %25 is encoded % sign.
    So you can try
    https://graph.microsoft.com/v1.0/groups?$select=id,displayName,description&$search="displayName:%2523"

    Does it work for you? Do you experience similar issues with any other symbols?

    Regards,
    Oleksandr

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful