2

Requirement is to list the available time slots in Microsoft Booking when the customer chose a particular service. This will be related to all the booking made that day for the selected services, working hours of the staff who work on these services and the time frame for the selected service.

For example if the service A takes 1 hour and the working time is from 08:00 to 17: 00. Time slots will be 08:00-09:00, 09:00-10:00 etc. Now, say if there are two staffs and the slot 11:00 - 12:00 is booked for both of them, then it should be excluded when we display the available slots. Also, if only one of the staff is booked for 11:00-12:00, then include it in the available slots as one staff is free for service.

Following the APIs in Use the Microsoft Bookings API in Microsoft Graph to implement this requirement. Can someone help with an approach with available APIs?

Sneha Dominic
  • 368
  • 2
  • 14
  • You can use the below call to get the appointments on that particular date which gives you many properties like serviceName,staffmemberIds, customerName,Start and end of appointment. In this call I have first got the bookingappointments on a particular date range(2nd Nov 2020) and then filtered according to the serviceName which results in the apppointments for the serviceName on that particular date. You can use $select query parameter to get specific properties. – Shiva Keshav Varma Nov 26 '20 at 12:58
  • The call is - `https://graph.microsoft.com/beta/bookingBusinesses/{bookingBusinessid}/calendarView?start=2020-11-02T00:00:00Z&end=2020-11-03T00:00:00Z&$select=customerName,serviceName,staffMemberIds,start,end&$filter=serviceName eq 'servicename'` – Shiva Keshav Varma Nov 26 '20 at 12:58
  • You can get the staff members workinghours using `https://graph.microsoft.com/beta/bookingBusinesses/TestBookingCalendar@Nishantsingh.live/staffMembers`. You need to code on your end comparing these 2 data and display according to your requirement. – Shiva Keshav Varma Nov 26 '20 at 13:05
  • Moving this to Answer. – Shiva Keshav Varma Nov 26 '20 at 13:20

2 Answers2

3

Answering my question with the solution approach implemented. Thanks for the insights @Shiva-MSFTIdentity.

Idea is to display the available time slots all throughout the business hours for a particular steps. Source code samples are in C# language. Steps that can be used are:

  1. Get the store business hours.

    BookingBusiness businessObject = await graphServiceClient.BookingBusinesses[StoreName].Request().Select(x => new { x.BusinessHours }).GetAsync();

  2. Get the details of service like the duration, staffmemberIds etc

    BookingService serviceObject = await graphServiceClient.BookingBusinesses[StoreName].Services[serviceId].Request().GetAsync();

  3. Now with the store hours and duration of service in hand, divide and create multiple time slots of duration length. For ex; if store hours is 08:00 - 17:00, slots for a service of duration 60 mins are 08:00 - 09:00, 09:00-10:00, 11:00 - 12:00 etc. If postBuffer and preBuffers are considered, include it here.

  4. Fetch the staff member details and for all staff who provide the selected service, check if they use business hours or not. If not, store their working hours.

    IBookingBusinessStaffMembersCollectionPage staffMemberCollection = await graphServiceClient.BookingBusinesses[StoreName].StaffMembers.Request().GetAsync()

  5. Next step is to fetch the appointments for the day. We need to store the details startTime, endTime, staffmemberIds of these appointments.

    IBookingBusinessCalendarViewCollectionPage calendarView = await graphServiceClient.BookingBusinesses[StoreName].CalendarView.Request(queryOptions).Filter(filterString).GetAsync();

  6. Once we have collected all the required data, for each time slot,

  • check if an appointment falls into it. If yes, mark the staffMemberIds as booked for the slot.
  • If count of booked staffmembers is equal to count of staff members prividing service implies, slot is booked.
  • Else find the list of pending staffmembers who can provide the servicve and check if they are available based on their working hours.
  • If atleast one staff is available, mark slot as available. Else, its booked.
Sneha Dominic
  • 368
  • 2
  • 14
1

You can use the below call to get the appointments on that particular date which gives you many properties like serviceName,staffmemberIds, customerName,Start and end of appointment. In this call I have first got the bookingappointments on a particular date range(2nd Nov 2020) and then filtered according to the serviceName which results in the apppointments for the serviceName on that particular date. You can use $select query parameter to get specific properties.

The call is -

https://graph.microsoft.com/beta/bookingBusinesses/{bookingBusinessid}/calendarView?start=2020-11-02T00:00:00Z&end=2020-11-03T00:00:00Z&$select=customerName,serviceName,staffMemberIds,start,end&$filter=serviceName eq 'servicename'

You can get the staff members workinghours using this call.

https://graph.microsoft.com/beta/bookingBusinesses/{BookingBusinessid}/staffMembers

You need to code on your end comparing these 2 data and display according to your requirement.

Shiva Keshav Varma
  • 3,398
  • 2
  • 9
  • 13