You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Microsoft Graph API创建年度重复日历事件的正确方法及起始日期异常问题排查

Creating a Yearly Recurring Event on the 3rd Tuesday of August via 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 startDate in the recurrence range exactly matches your first event date (2021-08-17) to keep the initial occurrence and recurrence pattern in sync.
  • Adjust the endDate to 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 start and end date-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 timeZone is consistent across all date-time fields to prevent time zone-related shifts.

内容的提问来源于stack exchange,提问作者Houy Narun

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 08:49:07