Search code examples
c#microsoft-graph-apioffice365microsoft-graph-sdksmicrosoft-graph-calendar

return a groups event using the c# microsoft graph sdk


I am a bit new to microsoft graph api.
I am attempting to get all events for an office 365 group I successfully got the results back microsoft graph explorer https://developer.microsoft.com/en-us/graph/graph-explorer

using the query https://graph.microsoft.com/v1.0/groups/88d59881-7b15-4adc-a756-5d10681cf99d/events

however I can't quite figure out how to do the same using the c# sdk. I can get the group information but I don't know how to get the array of events.

here is how I get the group information. but I'm unsure how to add in the events I now in ef core it would be groups.include(x => x.events) but that doesn't seem to work using microsoft graph sdk.

public  static Task<Group> GetGroup()
{
    EnsureGraphForAppOnlyAuth();
    // Ensure client isn't null
    _ = _appClient ??
        throw new System.NullReferenceException("Graph has not been initialized for app-only auth");

    return _appClient.Groups["88d59881-7b15-4adc-a756-5d10681cf99d"]
        .Request()
        .Select(u => new
        {
            // Only request specific properties
            u.DisplayName,
            u.Id,
            u.Description
        })
        .GetAsync();
}

Solution

  • Graph API Explorer has a tab Code snippets where you can find how to rewrite the query by using SDK for selected language.

    enter image description here