Denys Demchenko
Denys Demchenko

Reputation: 218

Get another User events using MS Graph API

I`m using https://github.com/microsoftgraph/aspnet-snippets-sample sample to access my AD using Graph API, but I need to get events of specific user. There are only sample for getting my events:

public async Task<List<ResultsItem>> GetMyEvents(GraphServiceClient graphClient)
{
    List<ResultsItem> items = new List<ResultsItem>();

    // Get events.
    IUserEventsCollectionPage events = await graphClient.Me.Events.Request().GetAsync();

    if (events?.Count > 0)
    {
        foreach (Event current in events)
        {
            items.Add(new ResultsItem
            {
                Display = current.Subject,
                Id = current.Id
            });
        }
    }
    return items;
}

And according to guide I should request

GET /users/{id | userPrincipalName}/calendar/events

To access another user events, but how? There is no possibility to get events from Users prop:

graphClient.Users[id].Request();

Please explain me. Every info will be usefull.

Upvotes: 2

Views: 1651

Answers (1)

RasmusW
RasmusW

Reputation: 3461

You can get to the events from the users property:

var events = await graphClient.Users[userid].Events.Request().GetAsync();

Upvotes: 3

Related Questions