msgraph-sdk-javascript
msgraph-sdk-javascript copied to clipboard
$search parameter not being interpolated with quotes into endpoint?
Bug Report
Prerequisites
- [x] Can you reproduce the problem?
- yes
- [x] Are you running the latest version?
- yes
- [x] Are you reporting to the correct repository?
- yes
- [x] Did you perform a cursory search?
- yes
For more information, see the CONTRIBUTING
guide.
Description
The project I am working on uses @microsoft/microsoft-graph-client in a react application to instantiate an api client and query the tenant user data according to some search parameter (searchInput
). While building out this search feature, I encountered the following errors when interpolating the search criteria into the argument to $search. From the HTTPMessageHandler output, I can see that displayName:aname
is being inserted into the endpoint without double quotes, as is demonstrated on this page (https://docs.microsoft.com/en-us/graph/api/user-list?view=graph-rest-1.0&tabs=http, see example 6). This leads to a syntax error from Graph. I can get around the error by directly interpolating the search criteria into the endpoint, see blow
Console Errors: [Is there any console error] see below
Errors:
HTTPMessageHandler.ts:29 GET https://graph.microsoft.com/v1.0/users?$search=displayName:aname&$orderby=displayName 400 (Bad Request)
index.js:1 Error: Syntax error: character ':' is not valid at position 11 in 'displayName:aname'.
at Function.constructErrorFromResponse (GraphErrorHandler.ts:76)
at Function.<anonymous> (GraphErrorHandler.ts:102)
at Generator.next (<anonymous>)
at tslib.es6.js:76
at new Promise (<anonymous>)
at __awaiter (tslib.es6.js:72)
at Function.getError (GraphErrorHandler.ts:99)
at GraphRequest.<anonymous> (GraphRequest.ts:391)
at Generator.throw (<anonymous>)
at rejected (tslib.es6.js:74)
Code to Reproduce error:
const options = {
authProvider,
};
const client = Client.init(options);
let response = await client
.api('/users')
.header('ConsistencyLevel', 'eventual')
.search(`displayName:${searchInput}`)
.orderby('displayName')
.get();
Workaround:
const options = {
authProvider,
};
const client = Client.init(options);
let response = await client
.api(`/users?$search="displayName:${searchInput}"&$count=true`)
.header('ConsistencyLevel', 'eventual')
.orderby('displayName')
.get();
Expected behavior: [What you expected to happen]
to query the user data using the displayName criteria as a search parameter
Actual behavior: [What actually happened]
gives syntax error
Usage Information
Request ID - Value of the requestId
field if you are receiving a Graph API error response
SDK Version - [SDK version you are using]
"@microsoft/microsoft-graph-client": "^3.0.0"
- [ X ] Node (Check, if using Node version of SDK)
Node Version - [The version of Node you are using]
14.17.6
- [ ] Browser (Check, if using Browser version of SDK)
Browser Name - [The name of Browser that you are using for SDK]
Version - [The version of the browser you are using]
@jacksonR5Star Thanks for reporting this issue! I will take a look at this shortly.
closing older issues.