Home > Net >  Cannot retrieve all instances of a recurring event
Cannot retrieve all instances of a recurring event

Time:10-28

It seems that retrieving instances after creating a recurring event does not always return more than 10 instances.

For example, if an event is created as follows, 11 instances will be created.

var @event = new Event
{
    Subject = "Subject",
    Body = new ItemBody
    {
        ContentType = BodyType.Html,
        Content = "Content"
    },
    Start = new DateTimeTimeZone
    {
        DateTime = "2022-10-27T15:00:00",
        TimeZone = "Tokyo Standard Time"
    },
    End = new DateTimeTimeZone
    {
        DateTime = "2022-10-27T16:00:00",
        TimeZone = "Tokyo Standard Time"
    },
    Recurrence = new PatternedRecurrence
    {
        Pattern = new RecurrencePattern
        {
            Type = RecurrencePatternType.Weekly,
            Interval = 1,
            DaysOfWeek = new List<DayOfWeek>()
            {
                DayOfWeek.Thursday
            }
        },
        Range = new RecurrenceRange
        {
            Type = RecurrenceRangeType.EndDate,
            StartDate = new Date(2022,10,27),
            EndDate = new Date(2023,1,5)
        }
    },
    Location = new Location
    {
        DisplayName = "Location"
    },
    Attendees = new List<Attendee>()
    {
        new Attendee
        {
            EmailAddress = new EmailAddress
            {
                Address = "[email protected]",
                Name = "test"
            },
            Type = AttendeeType.Required
        }
    },
    AllowNewTimeProposals = false
};

However, the instance retrieval result will be 10.

var queryOptions = new List<QueryOption>()
{
    new QueryOption("startDateTime", "2022-10-27T00:00:00"),
    new QueryOption("endDateTime", "2023-01-06T00:00:00")
};
var instances = await graphClient.Users["{user-id}"].Events["{event-id}"].Instances.Request(queryOptions).GetAsync();

Is there any way to retrieve all instances of a recurring event?

CodePudding user response:

.Instances.Request(queryOptions).Top(20).GetAsync(); use OData query to gather top 20 result. It can solve the problem.

And the reason for only return 10 instances isn't mentioned in the api document so I can only consider it as the default expected behavior.

  • Related