Skip to content

Not able to post staff members through graph client #3138

@apamoorionestaff

Description

@apamoorionestaff

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:waiting-for-triageAn issue that is yet to be reviewed or assignedtype:bugA broken experience

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions