【问题标题】:Microsoft Graph API creating recurring event returns 500Microsoft Graph API 创建重复事件返回 500
【发布时间】:2026-02-05 11:00:01
【问题描述】:

我正在编写一个使用Microsoft Graph API v1.0 与 Office365 事件同步的应用程序。

创建单个事件时,该事件按预期创建:

Response Status Code: 201 Created
Request URL: https://graph.microsoft.com/v1.0/me/calendars/<myCalendarId>/events
Request Method: POST
Request Payload:
{
    "subject": "single event",
    "start": {
        "dateTime": "2020-02-15T09:00:00",
        "timeZone": "Europe/Berlin"
    },
    "end": {
        "dateTime": "2020-02-15T10:00:00",
        "timeZone": "Europe/Berlin"
    },
    "attendees": [],
    "type": "singleInstance",
    "location": {
        "displayName": null
    },
    "recurrence": null
}

但是,如果我为重复事件发送创建请求,则会收到错误响应。

Response Status Code: 500 Internal Server Error
Request URL: https://graph.microsoft.com/v1.0/me/calendars/<myCalendarId>/events
Request Method: POST
Request Payload:
{
    "subject": "test recurring event",
    "start": {
        "dateTime": "2020-02-14T09:00:00",
        "timeZone": "Europe/Berlin"
    },
    "end": {
        "dateTime": "2020-02-14T10:00:00",
        "timeZone": "Europe/Berlin"
    },
    "attendees": [],
    "location": {
        "displayName": null
    },
    "recurrence": {
        "pattern": {
            "daysOfWeek": [],
            "type": "daily"
        },
        "range": {
            "numberOfOccurrences": "2",
            "recurrenceTimeZone": "Europe/Berlin",
            "startDate": "2020-02-14",
            "type": "numbered"
        }
    }
}
Response Body:
{
  "error": {
    "code": "ErrorInternalServerError",
    "message": "An internal server error occurred. The operation failed.",
    "innerError": {
      "request-id": "2d97931c-e08c-45a8-8167-5849df53a694",
      "date": "2020-02-14T14:38:28"
    }
  }
}

我觉得奇怪的是添加重复设置会导致Internal Server Error。 如何使用 API 创建重复事件?

【问题讨论】:

  • 响应 body 包含什么?通常,您会在其中发现人类可读的错误消息或类似内容。
  • 我已经编辑了问题并添加了响应正文。
  • 好吧,如果他们真的没有给你更多,你实际上需要问 MS。有时,此类 API 会以 500 错误代码响应,而在 400 Bad Request 或类似情况更合适的地方。然后您通常会收到一条消息,说明该请求有什么特别错误的地方。但如果这是一个“正版”500,那么可能只有 MS 才能告诉你,哪里出了问题。有时这些只是暂时的问题,所以也许在几个小时左右再试一次。否则,您可能必须找到提交错误报告的地方。

标签: microsoft-graph-calendar


【解决方案1】:

如果你想创建一个每天发生的重复事件,而不是通过以下方式设置模式:

    "pattern": {
        "daysOfWeek": [],
        "type": "daily"
    },

请这样设置模式:

"pattern": {
  "type": "daily",
  "interval": 1
},

概念文档中的here 描述了创建每日重复模式。第二天,参考文档中还会有一个REST example

【讨论】:

  • 谢谢,这解决了我的问题。我在docs 中看到intervalrequired。那不应该返回400 Bad Request 而不是500 Internal Server Error吗?
  • absoluteYearly 模式也有类似问题,请求中缺少索引,API 返回 500 错误,这很不酷