Microsoft Graph API创建年度重复日历事件的正确方法及起始日期异常问题排查
Let’s break down your questions and fix the issue step by step:
1. Correct Way to Create the Yearly Recurring Event
To create an event that repeats every year on the 3rd Tuesday of August, you need to properly configure the recurrence.pattern properties for the relativeYearly type. The critical missing parameter in your original payload is relativeMonthDay, which specifies the ordinal position (1st, 2nd, 3rd, etc.) of the weekday in the target month.
Here’s the corrected payload and function:
async function createYearlyRecurringEvent() { const event = { body: { content: "<p>Post from console</p>", contentType: "html" }, end: { dateTime: "2021-08-17T23:59:59", timeZone: "Asia/Bangkok" }, // Match your desired event duration recurrence: { pattern: { daysOfWeek: ["Tuesday"], interval: 1, month: 8, relativeMonthDay: 3, // Specifies the 3rd occurrence of Tuesday in August type: "relativeYearly" }, range: { endDate: "2025-08-19", // 3rd Tuesday of August 2025 startDate: "2021-08-17", type: "endDate" } }, start: { dateTime: "2021-08-17T00:00:00", timeZone: "Asia/Bangkok" }, // Include specific time for clarity subject: "No title - testing" }; try { console.log("Sending event payload:", event); const createdEvent = await graphClient .api('/me/events') .post(event); console.log("Successfully created event:", createdEvent); } catch (error) { console.error("Error creating event:", error); } }
Key details for the recurrence setup:
relativeMonthDay: 3: This tells Microsoft Graph API you want the 3rd Tuesday of August each year, which aligns with your initial event date.- Ensure the
startDatein the recurrence range exactly matches your first event date (2021-08-17) to keep the initial occurrence and recurrence pattern in sync. - Adjust the
endDateto the 3rd Tuesday of your final target year (2025-08-19 in this case) to avoid mismatched end dates.
2. Why the Start Date Shifted to 2022-08-02, and How to Fix It
Root Cause
Your original payload didn’t include the relativeMonthDay parameter. When using type: "relativeYearly" without this ordinal value, Graph API defaults to interpreting the pattern as the 1st occurrence of the weekday in the month.
Since 2021-08-17 is the 3rd Tuesday of August, the API couldn’t reconcile this date with an unconfigured relative yearly pattern. It reset the recurrence to start from the next valid 1st Tuesday of August, which is 2022-08-02, causing the unexpected date shift.
Fix
Adding relativeMonthDay: 3 (as shown in the corrected code) explicitly defines the recurrence rule you want. This aligns the pattern with your initial event date, ensuring the event starts on 2021-08-17 and repeats correctly each year.
Double-check these additional details to avoid further issues:
- The
startandenddate-time values should match your desired event duration (e.g., if it’s an all-day event, use consistent date-only or full date-time values). - Confirm the
timeZoneis consistent across all date-time fields to prevent time zone-related shifts.
内容的提问来源于stack exchange,提问作者Houy Narun

