Search code examples
javamicrosoft-graph-apimicrosoft-graph-sdksmicrosoft-graph-teamsmicrosoft-graph-calendar

Understanding Microsoft graph /getSchedule Api functionality


I am trying to use graph /getSchedule api to check for meeting conflict. However I'm not quite about functionality and usage of request input field "availabilityViewInterval".

My basic requirement is to pass a start and end dateTime and see if the resource is available(free/busy). Although I am able to get that in /getSchedule Api but not sure on some of the fields in request and response.

  1. "availabilityViewInterval" : This is a request field and is stated in document as optional but while using graph client i need to pass value for this. It accepts int value from 5 to 1440 but not sure what it does and what is the value i should pass?

  2. "availabilityView": This is a response field and returns a string value. But i am unable to understand it. What is this value for and how is it calculated? what is its significance and how it can be utilized?

Request:

ICalendarGetScheduleCollectionPage response = graphClient.users("usrEmailAddress").calendars(calendar.id)
                .getSchedule(schedulesList,endTime,startTime,availabilityViewInterval)
                .buildRequest()
                .post();

Below is my sample response(both time the availabilityViewInterval value is 5 in request but response availabilityView is different):

**"availabilityView": "22"**,
      "scheduleItems": [
        {
          "isPrivate": false,
          "status": "busy",
          "subject": "Test Meeting again",
          "location": "",
          "start": {
            "dateTime": "2020-06-12T10:58:45.0000000",
            "timeZone": "UTC"
          },
          "end": {
            "dateTime": "2020-06-12T11:08:45.0000000",
            "timeZone": "UTC"
          }
        }
      ],
      "workingHours": {
        "daysOfWeek": [
          "monday",
          "tuesday",
          "wednesday",
          "thursday",
          "friday"
        ],
        "startTime": "08:00:00.0000000",
        "endTime": "17:00:00.0000000",
        "timeZone": {
          "name": "India Standard Time"
        }

Response 2:

**"availabilityView": "00"**,
      "scheduleItems": [],
      "workingHours": {
        "daysOfWeek": [
          "monday",
          "tuesday",
          "wednesday",
          "thursday",
          "friday"
        ],
        "startTime": "08:00:00.0000000",
        "endTime": "17:00:00.0000000",
        "timeZone": {
          "name": "India Standard Time"
        }

Response 3:

**"availabilityView": "220000000000"**,
      "scheduleItems": [
        {
          "isPrivate": false,
          "status": "busy",
          "subject": "Test Meeting again",
          "location": "",
          "start": {
            "dateTime": "2020-06-12T10:58:45.0000000",
            "timeZone": "UTC"
          },
          "end": {
            "dateTime": "2020-06-12T11:08:45.0000000",
            "timeZone": "UTC"
          }
        }
      ],
      "workingHours": {
        "daysOfWeek": [
          "monday",
          "tuesday",
          "wednesday",
          "thursday",
          "friday"
        ],
        "startTime": "08:00:00.0000000",
        "endTime": "17:00:00.0000000",
        "timeZone": {
          "name": "India Standard Time"
        }

Note: The start and end time for all the request were different but availabilityViewInterval field was 5 in all the cases.

I am referring below Microsoft document:

https://learn.microsoft.com/en-us/graph/api/calendar-getschedule?view=graph-rest-1.0&tabs=java

Please help me understand significance and usage of "availabilityViewInterval" in request and "availabilityView" in response. Also, will status value be only "free/busy" or it can have any other value too? Thanks in advance


Solution

  • The docs say:

    Represents the duration of a time slot in an availabilityView in the response. The default is 30 minutes, minimum is 5, maximum is 1440. Optional.

    What this signifies are the size of a time slot in the availabilityView. It's probably helpful to look at an example.

    Here's the sample request from the doc:

    {        
        "schedules": ["adelev@contoso.onmicrosoft.com", "meganb@contoso.onmicrosoft.com"],
        "startTime": {
            "dateTime": "2019-03-15T09:00:00",
            "timeZone": "Pacific Standard Time"
        },
        "endTime": {
            "dateTime": "2019-03-15T18:00:00",
            "timeZone": "Pacific Standard Time"
        },
        "availabilityViewInterval": 60
    }
    

    With availabilityViewInterval set to 60, that means each numeral in the returned availabilityView represents a 60 minute chunk of time. The sample response shows the value 200220010 for Megan. With 0 = free, 1 = tentative, and 2 = busy, we can decode this as:

    • 9AM - 10AM Busy
    • 10AM - 11AM Free
    • 11AM - 12PM Free
    • 12PM - 1PM Busy
    • 1PM - 2PM Busy
    • 2PM - 3PM Free
    • 3PM - 4PM Free
    • 4PM - 5PM Tentative
    • 5PM - 6PM Free

    If you did this same request with availabilityViewInterval set to 30, you'd get back an availabilityView value of 220000222200001100, each digit representing a 30 minute chunk of time.