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?