0

I am developing a portal for meeting room booking similar to the one available on Power Apps. I want to call graph API to get the availability of each rooms in the tenet at the filtered time provided by the user. But it only provides result for 3-4 rooms and HTTP 429 error for the rest of them.

I have even tried it using debounce but it only gives 1 result. Below is my code snippet

private async _getRooms(item: RoomListInfo): Promise<void> {
    this.setState({ rooms: [] });

    await this.props.context.msGraphClientFactory
      .getClient("3")
      .then((client: MSGraphClientV3): void => {
        // Get user information from the Microsoft Graph
        client
          .api(
            "places/" + item.emailAddress + "/microsoft.graph.roomlist/rooms"
          )
          .version("v1.0")
          .get((err, res: any) => {
            // handle the response
            if (err) {
              console.log("Error: ", err);
              return;
            }

            // Map the JSON response to the output array
            res.value.map((item: any) => {
              this._allRooms.push({
                displayName: item.displayName,
                emailAddress: item.emailAddress,
                capacity: item.capacity,
                id: item.id,
                availability: this._getAvailability(item),
              });
            });

            // Update the component state accordingly to the result
            this.setState({
              rooms: this._allRooms,
            });
          });
      });
  }
private _getAvailability = debounce((item) => {
    const start = this.state.selectedDate;
    const end = this.state.selectedDate;
    start.setUTCHours(this.state.selectedStart.getUTCHours());
    start.setUTCMinutes(this.state.selectedStart.getUTCMinutes());
    end.setUTCHours(this.state.selectedEnd.getUTCHours());
    end.setUTCMinutes(this.state.selectedEnd.getUTCMinutes());

    console.log(this.state.selectedStart, this.state.selectedEnd, start, end);

    const apiMail = {
      Schedules: [item.emailAddress],
      StartTime: {
        dateTime: this.formattedDateForAvailability(this.state.selectedStart),
        timeZone: "Central Standard Time",
      },
      EndTime: {
        dateTime: this.formattedDateForAvailability(this.state.selectedEnd),
        timeZone: "Central Standard Time",
      },
      availabilityViewInterval: "30",
    };

    this.props.context.msGraphClientFactory
      .getClient("3")
      .then((client: MSGraphClientV3): void => {
        client
          .api("me/calendar/getschedule")
          .version("v1.0")
          .post(apiMail)
          .then((res) => {
            console.log(res);

            res.value.map((x: any) => {
              console.log("Availability: ", x);
              if (x.availabilityView !== "0") {
                console.log("Busy found: ", item.emailAddress);
                return false;
              }
            });
          });
      });

    return true;
  }, 500);

How to get result for all the rooms without causing 429 error?

Neel Shah
  • 26
  • 4

2 Answers2

1

You will need to create on the code a back-off rule to avoid getting throttled. The limits for the service should be on the page of the API.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 09 '23 at 20:29
0

It looks like you're using the exact same date/time for both the START and END filter on your call.

const start = this.state.selectedDate;
const end = this.state.selectedDate;

As a result, I believe Graph is trying to return your entire calendar schedule which results in too many API calls on the back end thus producing the 429 throttling errors you're seeing. Try using a small date range like a single day for example.