更新日历

命名空间:microsoft.graph

更新 calendar 对象的属性。 可以是用户的日历,也可以是 Microsoft 365 的默认日历。

权限

根据事件所处日历类型和所请求的权限类型(委派型或应用程序),需要下列某一权限来调用此 API。 要了解详细信息(包括如何选择权限),请参阅权限

日历 委派(工作或学校帐户) 委派(个人 Microsoft 帐户) 应用程序
用户日历 Calendars.ReadWrite Calendars.ReadWrite Calendars.ReadWrite
组日历 Group.ReadWrite.All 不支持。 不支持。

HTTP 请求

用户或组的默认 日历

PATCH /me/calendar
PATCH /users/{id | userPrincipalName}/calendar
PATCH /groups/{id}/calendar

默认 calendarGroup 中用户的 日历

PATCH /me/calendars/{id}
PATCH /users/{id | userPrincipalName}/calendars/{id}

指定 calendarGroup 中用户的 日历

PATCH /me/calendarGroups/{id}/calendars/{id}
PATCH /users/{id | userPrincipalName}/calendarGroups/{id}/calendars/{id}

请求标头

标头
Authorization Bearer {token}。必需。
Content-Type application/json. Required.

请求正文

在请求正文中,提供应更新的相关字段的值。请求正文中不包括的现有属性将保留其以前的值,或根据对其他属性值的更改重新计算。为了获得最佳性能,不应包括尚未更改的现有值。

属性 类型 说明
color String 在 UI 中指定将该日历与其他日历区分开来的颜色主题。属性值有:LightBlue=0、LightGreen=1、LightOrange=2、LightGray=3、LightYellow=4、LightTeal=5、LightPink=6、LightBrown=7、LightRed=8、MaxColor=9、Auto=-1
isDefaultCalendar Boolean 如果此日历是用户的默认日历,则值为 true,否则为 false。
name String 日历名称。

响应

如果成功,此方法在响应正文中返回 200 OK 响应代码和更新的 calendar 对象。

示例

请求

以下示例更新已登录用户的默认日历的名称。

PATCH https://graph.microsoft.com/v1.0/me/calendar
Content-type: application/json

{
  "name": "Social events"
}

响应

这是一个示例响应。注意:为提高可读性,可能缩短了此处显示的响应对象。

HTTP/1.1 200 OK
Content-type: application/json

{
    "@odata.context":"https://graph.microsoft.com/v1.0/$metadata#me/calendars/$entity",
    "@odata.id":"https://graph.microsoft.com/v1.0/users('266efe5a-0fd7-4edd-877b-b2d1e561f193@ae01a323-3934-4475-a32d-af1274312bb0')/calendars('AAMkADJmMVAAA=')",
    "id":"AAMkADJmMVAAA=",
    "name":"Social events",
    "color":"auto",
    "isDefaultCalendar":false,
    "changeKey":"DxYSthXJXEWwAQSYQnXvIgAAIxGttg==",
    "canShare":true,
    "canViewPrivateItems":true,
    "hexColor": "",
    "canEdit":true,
    "allowedOnlineMeetingProviders": [
                "teamsForBusiness"
            ],
    "defaultOnlineMeetingProvider": "teamsForBusiness",
    "isTallyingResponses": true,
    "isRemovable": false,
    "owner":{
        "name":"Samantha Booth",
        "address":"samanthab@adatum.onmicrosoft.com"
    }
}