How to get events info of given Room ID in payload like subject, location etc. using microsoft graph calendar getSchedule API and service principal / App access token.

Ashish Banjare 0 Reputation points
2023-06-29T06:50:26.0366667+00:00

Hello There,

I am trying to get events info of Teams Rooms by Room ID from Calendar getSchedule API using service principal or App access token.

In my Application i need information of events like subject, location, start time and end time at particular date.

so i called api POST https://graph.microsoft.com/v1.0/users/{user_id/UserPrincipalName}/calendar/getSchedule Where UserPrincipalName is "******@test.com"

Then pass request payload.

{
    "schedules": ["******@test.com", "******@test.com"],
    "startTime": {
        "dateTime": "2023-06-27T00:00:00",
        "timeZone": "India Standard Time"
    },
    "endTime": {
        "dateTime": "2023-06-27T23:59:59",
        "timeZone": "India Standard Time"
    },
    "availabilityViewInterval": 30
}

I received response.

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.scheduleInformation)",
    "value": [
        {
            "scheduleId": "******@test.com",
            "availabilityView": "000000000000000000000000000000000000000000000000",
            "scheduleItems": [],
            "workingHours": {
                "daysOfWeek": [
                    "monday",
                    "tuesday",
                    "wednesday",
                    "thursday",
                    "friday"
                ],
                "startTime": "08:00:00.0000000",
                "endTime": "17:00:00.0000000",
                "timeZone": {
                    "name": "Pacific Standard Time"
                }
            }
        },
        {
            "scheduleId": "******@test.com",
            "availabilityView": "000000000000000000000000000202002020002000000000",
            "scheduleItems": [
                {
                    "status": "busy",
                    "start": {
                        "dateTime": "2023-06-27T13:30:00.0000000",
                        "timeZone": "India Standard Time"
                    },
                    "end": {
                        "dateTime": "2023-06-27T14:00:00.0000000",
                        "timeZone": "India Standard Time"
                    }
                },
                {
                    "status": "busy",
                    "start": {
                        "dateTime": "2023-06-27T14:30:00.0000000",
                        "timeZone": "India Standard Time"
                    },
                    "end": {
                        "dateTime": "2023-06-27T15:00:00.0000000",
                        "timeZone": "India Standard Time"
                    }
                }
            ],
            "workingHours": {
                "daysOfWeek": [
                    "monday",
                    "tuesday",
                    "wednesday",
                    "thursday",
                    "friday"
                ],
                "startTime": "08:00:00.0000000",
                "endTime": "17:00:00.0000000",
                "timeZone": {
                    "name": "Pacific Standard Time"
                }
            }
        }
    ]
}

But my problems are

  1. I am not able to get response of events info like Subject, location except start time, end time and status from given payload "schedules": ["@test.com", "@test.com"].

enter image description here

Thanks you so much

Microsoft Teams | Development
Microsoft Security | Microsoft Graph
Microsoft Teams | Microsoft Teams for business | Other
{count} votes

2 answers

Sort by: Most helpful
  1. Nivedipa-MSFT 3,646 Reputation points Microsoft External Staff Moderator
    2023-06-30T07:21:44.85+00:00

    @Ashish Banjare - Thanks for reporting your issue.
    getSchedule API call contains information about the availability and schedule items for the specified rooms.
    To get the detailed information of events (including Subject, Location, etc.), you'll need to call the get event API to retrieve the event details for each schedule item.

    GET https://graph.microsoft.com/v1.0/me/events/{event_id}

    Ref Doc: https://learn.microsoft.com/en-us/graph/api/event-get?view=graph-rest-1.0&tabs=http

    Thanks,

    Nivedipa


    If the response is helpful, please click "Accept Answer" and upvote it. You can share your feedback via Microsoft Teams Developer Feedback link. Click here to escalate.

    1 person found this answer helpful.
    0 comments No comments

  2. Hacker44 0 Reputation points
    2023-08-01T12:52:28.9966667+00:00
    
    To get events information of a given Room ID using the Microsoft Graph API's getSchedule endpoint with a service principal / app access token, you can follow these steps:
    
    Register your application and grant it the necessary permissions:
    
    Make sure you have registered your application in the Azure AD and obtained the necessary permissions to access calendar information.
    Your application should have the "Calendars.Read" or "Calendars.Read.All" application permission to read calendar events.
    Acquire an access token using the client credentials flow (service principal):
    
    Using the client credentials flow, your application can request an access token without a user's involvement. 
    Send a POST request to the token endpoint (https://login.microsoftonline.com/{tenant_id}/oauth2/token) with the necessary parameters (client_id, client_secret, grant_type, and resource).
    Make a request to the getSchedule API:
    
    Use the acquired access token in the Authorization header of the API request to authenticate.
    The getSchedule API allows you to retrieve the free/busy information of a room, but it does not return the details of individual events (like subject, location, etc.). To get event details, you will need to use the List events API to fetch event details separately.
    Here's an example of how to make the request:
    
    bash
    Copy code
    # Replace these placeholders with actual values
    ROOM_ID = "room_id_here"
    ACCESS_TOKEN = "access_token_here"
    
    # Make the request to get the schedule (free/busy information)
    curl -X GET \
      'https://graph.microsoft.com/v1.0/me/calendar/getSchedule' \
      -H 'Authorization: Bearer $ACCESS_TOKEN' \
      -H 'Content-Type: application/json' \
      -d '{
        "schedules": ["ROOM_ID"],
        "startTime": "2023-08-01T00:00:00Z",
        "endTime": "2023-08-02T00:00:00Z",
        "availabilityViewInterval": "60"
      }'
    Please note that the getSchedule API provides only the availability (free/busy) information, not the event details. To get the event details, you will need to use the List events API with the Room ID to fetch the details of the events scheduled for that room. 
     
    bash
    Copy code
    # Replace these placeholders with actual values
    ROOM_ID = "room_id_here"
    ACCESS_TOKEN = "access_token_here"
    
    # Make the request to get events for the given room
    curl -X GET \
      "https://graph.microsoft.com/v1.0/users/$ROOM_ID/events" \
      -H "Authorization: Bearer $ACCESS_TOKEN" \
      -H "Content-Type: application/json"
    This request will give you the event details for the given Room ID, such as subject, location, and other relevant information.
    
    Remember to replace ROOM_ID and ACCESS_TOKEN with the actual values in your code. Additionally, make sure your application has the required permissions to access calendars and events.
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.