Microsoft graph api calendarview migration

Viewed 158

I am using below url for calls to ms graph api. Now I migrate to use the nuget Microsoft.Graph (GraphServiceClient) instead. In ms graph api explorer the call is working as expected but not with the nuget. Any ideas?

I have tried some variants now but can´t get the same answer.
Request:

https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/calendar/calendarView?startDateTime=2021-08-19T09:22:00.6654083Z&endDateTime=2021-08-30T09:22:00.6654083Z&showAs=free&$select=showAs,start,end&$top=1000

My code attempt that are not working is

 QueryOption startDateTime = new QueryOption("startDateTime", startDate.ToString("o"));
            QueryOption endDateTime = new QueryOption("endDateTime", endDate.ToString("o"));
            List<Option> options = new List<Option>();
            options.Add(startDateTime);
            options.Add(endDateTime);

            var items= await _graphServiceClient
                                    .Users[profileName]
                                    .Calendar
                                    .CalendarView
                                    .Request(options)
                                    .GetAsync();
2 Answers

In ms graph apiexplorer there is a "nice" function, new for me mayby for some more.

When you run the query with right answer. In the answer box the there is an "Code snippets" tab/button and then you see needed code. For me in CSharp.

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var queryOptions = new List<QueryOption>()
{
    new QueryOption("startDateTime", "2021-08-19T09:22:00.6654083Z"),
    new QueryOption("endDateTime", "2021-08-30T09:22:00.6654083Z"),
    new QueryOption("showAs", "free")
};

var calendarView = await graphClient.Users[profileName].Calendar.CalendarView
    .Request( queryOptions )
    .Select("showAs,start,end")
    .Top(1000)
    .GetAsync();
 var queryOptions = new List<QueryOption>()
            {
                new QueryOption("startDateTime", from.ConvertDateTimeToUtc(timeZone.WinTimeZone).ConvertDateTimeToUtcIso8601String()),
                new QueryOption("endDateTime", to.ConvertDateTimeToUtc(timeZone.WinTimeZone).ConvertDateTimeToUtcIso8601String()),
            };

var calendarView = await graphClient.Users[profileName].Calendar.CalendarView
.Request(queryOptions)
.GetAsync();
.GetAsync();
Related