microsoftgraph / microsoftgraph/msgraph-sdk-dotnet

Not able to post staff members through graph client

Open
#3,138 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status:waiting-for-triage type:bug
Dominant language
C#
Stars
789
Forks
264
Avg merge
15h 17m
Merged PRs (30d)
3

Description

I integrated microsoft bookings into our dotnet app through Microsoft Graph API v5.38. When this was first setup, the Role property Enum had the Role as teamMember, but was not acceptd by the API's, and failing with an OData error. Finally, after multiple hit-and-trails, I was able to send the request as follows, and that worked fine(Though the staffs added this way were not able to access the shared bookings page directly).

// Function to add staff to the common bookings page
    private async Task<string> AddStaffToBookingBusiness(Staff staff)
    {
        var requestBody = new BookingStaffMember
        {
            DisplayName = staff.FullName,
            EmailAddress = staff.WorkEmail,
            AvailabilityIsAffectedByPersonalCalendar = true,
            UseBusinessHours = true,
            IsEmailNotificationEnabled = true,
            // Wrong Enum. Must be fixed by microsoft.
            // https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/2819
            // Role = BookingStaffRole.TeamMember
            AdditionalData = new Dictionary<string, object>
            {
                { "role", "member" }
            }
        };

        try
        {
            var res = await graphClient.Solutions.BookingBusinesses[_bookingId].StaffMembers.PostAsync(requestBody);
            return res?.Id ?? "";
        }
        catch (Exception ex)
        {
            throw new ApiException(ex.Message, HttpStatusCode.InternalServerError);
        }
    }

But this stopped working since few weeks. No matter what i send in the body, It's always returning an unknown error, or an ODATAERROR.

I tried using the code from official docs too, but nothing seems to work. I included the required fields, according to the documentation:

var requestBody = new BookingStaffMember
        {
            OdataType = "#microsoft.graph.bookingStaffMember",
            DisplayName = staff.FullName,
            EmailAddress = staff.WorkEmail,
            Role = BookingStaffRole.TeamMember,
            UseBusinessHours = true,
            TimeZone = "Central Standard Time",
            WorkingHours =
            [
                new BookingWorkHours
                {
                    OdataType = "#microsoft.graph.bookingWorkHours",
                    Day = DayOfWeekObject.Sunday,
                    TimeSlots =
                    [
                        new BookingWorkTimeSlot
                        {
                            OdataType = "#microsoft.graph.bookingWorkTimeSlot",
                            EndTime = new Time(DateTime.Parse("17:00:00.0000000")),
                            StartTime = new Time(DateTime.Parse("08:00:00.0000000")),
                        }
                    ],
                    AdditionalData = new Dictionary<string, object>
                    {
                        {
                            "day@odata.type", "#microsoft.graph.dayOfWeek"
                        },
                        {
                            "timeSlots@odata.type", "#Collection(microsoft.graph.bookingWorkTimeSlot)"
                        }
                    }
                },
            ],
            IsEmailNotificationEnabled = false,
            AdditionalData = new Dictionary<string, object>
            {
                {
                    "role@odata.type", "#microsoft.graph.bookingStaffRole"
                },
                {
                    "workingHours@odata.type", "#Collection(microsoft.graph.bookingWorkHours)"
                },
            }
        };


In some cases, it adds the staff to the bookings business, even though it sends me back an error. I am guessing it's because of the BookingStaffRole.TeamMember enum.

Expected behavior

The Post request must successfully create the StaffMember with teamMember role, and the user must be able to access the bookings page.

How to reproduce

Try to add a StaffMember to an existing bookings business.

SDK Version

5.38.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output
Click to expand log Image Image
Configuration

No response

Other information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the AddStaffToBookingBusiness entry point and the graphClient.Solutions.BookingBusinesses[_bookingId].StaffMembers.PostAsync call, comparing the two BookingStaffMember request bodies shown. Reproduce the request against an existing bookings business and inspect the returned OData or unknown error; done means a staff member with the teamMember role is created successfully and can access the bookings page.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.