Skip to content

GraphClient fail to fetch User if UPN start with $(dollar sign) #2635

@yejingyu

Description

@yejingyu

Describe the bug

Based on the userPrincipalName section of this documentation, An UPN starts with $ (dollar sign) is a valid UPN. However, if we pass in a UPN starting with $, we would get an error saying:

Microsoft.Graph.Models.ODataErrors.ODataError: The request URI is not valid. Since the segment 'users' refers to a collection, this must be the last segment in the request URI or it must be followed by an function or action that can be bound to it otherwise all intermediate segments must refer to a single resource.

Expected behavior

If the UPN is valid, we should be able to get the user without any error.

How to reproduce

Using the code below:

var upn = "$abc@def.com";

User user = await graphClient
  .Users[upn]
  .GetAsync(requestConfiguration =>
  {
      requestConfiguration.QueryParameters.Select = new string[] { "id", "UserPrincipalName" };
  })
  .ConfigureAwait(false);

we can also trigger the same error (link) in the Graph Explorer playground.

SDK Version

5.46.0

Latest version known to work for scenario above?

No response

Known Workarounds

N/A
Previously we called Graph with HTTP Client and HttpUtility.UrlEncode(upn) works. However, because the Graph SDK 5.0 is doing the encoding, double encoding would only make the problem worse.

Debug output

No response

Configuration

No response

Other information

Based on this thread, it is a known feature when calling the Graph API. we have different API syntax for UPN starting with $.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions