You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to find a user and a selection of their properties through their email. Currently I'm building a filter to find said user like so:
filter: identities/any(id:id/issuer eq ' ' and id/issuerAssignedId eq '{emailAddress}')
For most email addresses, the filtering works as expected for both direct requests using _GraphServiceClient.Users.GetAsync() as well as batch requests and building the requests with _GraphServiceClient.Users.ToGetRequestInformation().
I've noticed that some of our users aren't returned by the batch requests but provide valid responses through a direct request.
The emails have in common that they contain a '+' character, e.g. [email protected]. Upon further investigation I've noticed that the Graph API can't handle the '+' character and needs it to be escaped.
Apparently, the filter string is escaped when requesting _GraphServiceClient.Users.GetAsync() but not when using _GraphServiceClient.Users.ToGetRequestInformation() followed by a batch request.
Expected behavior
The filter behaviour should be equal throughout the SDK and not differ between usages. I believe the filter should also be escaped when build a request and sending it through a batch request.
How to reproduce
Assuming I have a list of emails for which I want some B2C properties like the display name.
When I use the the SDK by sending the requests one by one like so, everything works as expected:
But creating a batch request when the list of email addresses might become bigger creates empty results for emails with a '+' character. The request is built like this:
varbatchRequestContent=new BatchRequestContentCollection(_GraphServiceClient);varrequestIdsForEmails=newDictionary<string,string>();foreach(var emailAddress in emailAddresses){varidentityRequest= _GraphServiceClient.Users.ToGetRequestInformation(requestConfig =>{ requestConfig.QueryParameters.Select =UserSelections; requestConfig.QueryParameters.Filter =$"identities/any(id:id/issuer eq ' ' and id/issuerAssignedId eq '{emailAddress}')"});varidentityRequestId=await batchRequestContent.AddBatchRequestStepAsync(identityRequest);
requestIdsForEmails.Add(emailAddress,[identityRequestId, otherMailRequestId]);}varbatchResponse=await _GraphServiceClient.Batch.PostAsync(batchRequestContent, cancellationToken);varemailsWithUsers=newDictionary<string,IEnumerable<User>>();foreach(var emailWithRequestIds in requestIdsForEmails){try{varuserResponse=await batchResponse.GetResponseByIdAsync<UserCollectionResponse>(emailWithRequestIds.Value);
emailsWithUsers.Add(emailWithRequestIds.Key, userResponse.Value);}catch(Exception){
emailsWithUsers.Add(emailWithRequestIds.Key,[]);}}returnemailsWithUsers;
SDK Version
5.59.0
Latest version known to work for scenario above?
No response
Known Workarounds
I've fixed the issue by explicitly escaping the emailAddress before using it in the filter:
But this creates an odd situation since escaping the emailAddress with a direct request to _GraphServiceClient.Users.GetAsync() breaks the direct request. So I need to handle the email addresses differently which creates a confusing situation in the code base.
Debug output
No response
Configuration
OS: Windows 11
architecture x64
Other information
No response
The text was updated successfully, but these errors were encountered:
noelroehrig
changed the title
Different URL escaping behaviour in batch and direct requests
Different filter escaping behaviour in batch and direct requests
Oct 14, 2024
Describe the bug
I'm trying to find a user and a selection of their properties through their email. Currently I'm building a filter to find said user like so:
identities/any(id:id/issuer eq ' ' and id/issuerAssignedId eq '{emailAddress}')
For most email addresses, the filtering works as expected for both direct requests using
_GraphServiceClient.Users.GetAsync()
as well as batch requests and building the requests with_GraphServiceClient.Users.ToGetRequestInformation()
.I've noticed that some of our users aren't returned by the batch requests but provide valid responses through a direct request.
The emails have in common that they contain a '+' character, e.g.
[email protected]
. Upon further investigation I've noticed that the Graph API can't handle the '+' character and needs it to be escaped.Apparently, the filter string is escaped when requesting
_GraphServiceClient.Users.GetAsync()
but not when using_GraphServiceClient.Users.ToGetRequestInformation()
followed by a batch request.Expected behavior
The filter behaviour should be equal throughout the SDK and not differ between usages. I believe the filter should also be escaped when build a request and sending it through a batch request.
How to reproduce
Assuming I have a list of emails for which I want some B2C properties like the display name.
When I use the the SDK by sending the requests one by one like so, everything works as expected:
But creating a batch request when the list of email addresses might become bigger creates empty results for emails with a '+' character. The request is built like this:
SDK Version
5.59.0
Latest version known to work for scenario above?
No response
Known Workarounds
I've fixed the issue by explicitly escaping the emailAddress before using it in the filter:
But this creates an odd situation since escaping the emailAddress with a direct request to
_GraphServiceClient.Users.GetAsync()
breaks the direct request. So I need to handle the email addresses differently which creates a confusing situation in the code base.Debug output
No response
Configuration
Other information
No response
The text was updated successfully, but these errors were encountered: