graphserviceclient throws exception when query users selecting birthday property

Hagen 30 Reputation points
2023-07-19T17:05:59.9566667+00:00

I have used the GraphServiceClient to query users from AD. In order to get a few non-default properties I passed a query parameters select array to the Users.GetAsync-method:

            var users = _gsclient.Users.GetAsync((rc) =>
            {
                rc.QueryParameters.Select = new string[]
                {   "id",
                    "userPrincipalName",
                    "givenName",
                    "surname",
                    "birthday",
                    "streetAddress",
                    "city",
                    "country",
                    "mail",
                    "employeeType",
                    "jobTitle",
                    "createdDateTime"
                };
            });

The call throws an error:

Microsoft.Graph.Models.ODataErrors.ODataError: Exception of type 'Microsoft.Graph.Models.ODataErrors.ODataError' was thrown.
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.ThrowIfFailedResponse(HttpResponseMessage response, Dictionary`2 errorMapping, Activity activityForAttributes)
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
   at Microsoft.Graph.Users.UsersRequestBuilder.GetAsync(Action`1 requestConfiguration, CancellationToken cancellationToken)
   at MY.API.Controllers.UserController.GetAll() in \MY.API\Controllers\UserController.cs:line 27

After removing the "birthday" property from the select-array it worked again. Later, I have discovered, that there is no field in the AD User management where I can maintain a user's birthday.

Is it possible that the exception is thrown because the birthday property actually does not exist (so, it is a bug)? If so, wouldn't it be better to remove the property from the Microsoft.Graph.Models.User-class? Thank you.

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 46,371 Reputation points
    2023-07-20T03:08:22.9966667+00:00

    Hi @Hagen

    This issue has been around for a while, currently there is no support for using $select to return the birthday of a user set, only the birthday of a specific user. Refer to similar thread on GitHub.

    So try removing the birthday attribute when listing the user set, or return the birthday for a specific user:

    var users = _gsclient.Users["{user-id}"].GetAsync((rc) =>
                {
                    rc.QueryParameters.Select = new string[]
                    {   "id",
                        "userPrincipalName",
                        "givenName",
                        "surname",
                        "birthday",
                        "streetAddress",
                        "city",
                        "country",
                        "mail",
                        "employeeType",
                        "jobTitle",
                        "createdDateTime"
                    };
                });
    

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.