Sort by
Newest
$search for directory objects fails for encoded ampersand (&) character
Active: 1 yearUpdated: August 22, 2023Area:Query parameters
As per RFC 3986 and as described in Encoding query parameters, reserved characters in query strings must be percent-encoded. For example, the syntax for $search on a group name like "Hiking&Recreation" is as follows:
GET https://graph.microsoft.com/v1.0/groups?$search="displayName:Hiking%26Recreation group"
Microsoft Graph currently returns a 400 Bad Request error code on the v1.0 endpoint on searches that include encoded ampersand (&) characters, with the following error message: Unrecognized query argument specified: ''.". The same request succeeds on the beta endpoint.
Some apps have implemented double-percent encoding on the v1.0 endpoint as a workaround. For example, the double-percent encoded request becomes `/users?$search="displayName:Hiking%2526Recreation group"`. However, this is not the officially recommended workaround.
Workaround
Workaround 1:
On the v1.0 endpoint, when using the proper percent-encoding, include the Prefer request header set to legacySearch=false. For example:
GET https://graph.microsoft.com/v1.0/groups?$search="displayName:Hiking%26Recreation group"
ConsistencyLevel: eventualPrefer: legacySearch=false
In the future, the behavior on the v1.0 endpoint will be corrected, and you will not need to include this header.
Workaround 2:
When the behavior on the v1.0 endpoint is corrected, apps that will have a dependency on the double-percent encoding may experience breaking changes unless they are opted-in to maintain their implementation by including the Prefer request header set to legacySearch=true. For example:
GET https://graph.microsoft.com/v1.0/groups?$search="displayName:Hiking%2526Recreation group"
ConsistencyLevel: eventualPrefer: legacySearch=true