创建 outlookTask(已弃用)
命名空间:microsoft.graph
重要
Microsoft Graph版本下的 /beta API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
在Outlook邮箱的默认任务组 () 和默认任务 () My Tasks Tasks 创建任务。
POST 方法始终忽略请求正文中 startDateTime 和 dueDateTime 的时间部分,并假定时间始终为指定时区中的午夜。
默认情况下,此操作 (GET、PATCH 和 完成 任务操作) UTC 格式返回与日期相关的属性。 你可以使用 Prefer: outlook.timezone 标头将响应中的所有与日期相关的属性都表示为与 UTC 不同的时区。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限。
| 权限类型 |
权限(从最低特权到最高特权) |
| 委派(工作或学校帐户) |
Tasks.ReadWrite |
| 委派(个人 Microsoft 帐户) |
Tasks.ReadWrite |
| 应用程序 |
不支持。 |
HTTP 请求
POST /me/outlook/tasks
POST /users/{id|userPrincipalName}/outlook/tasks
| 名称 |
说明 |
| Authorization |
Bearer {token}。必需。 |
| Prefer: outlook.timezone |
指定响应中时间属性的时区,如果未指定此标头,则其时区为 UTC。 可选。 |
请求正文
在请求正文中,提供 outlookTask 对象的 JSON 表示形式。
响应
如果成功,此方法在 201 Created 响应正文中返回 响应代码和 outlookTask 对象。
示例
请求
以下示例显示标头 Prefer: outlook.timezone 的使用。 它创建一个任务,用东部标准时间 (EST) 表示 startDateTime 和 dueDateTime, 并包括太平洋标准时间 (Prefer PST) 标头。
POST https://graph.microsoft.com/beta/me/outlook/tasks
Prefer: outlook.timezone="Pacific Standard Time"
Content-type: application/json
{
"subject": "Shop for children's weekend",
"startDateTime": {
"dateTime": "2016-05-03T09:00:00",
"timeZone": "Eastern Standard Time"
},
"dueDateTime": {
"dateTime": "2016-05-05T16:00:00",
"timeZone": "Eastern Standard Time"
}
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var outlookTask = new OutlookTask
{
Subject = "Shop for children's weekend",
StartDateTime = new DateTimeTimeZone
{
DateTime = "2016-05-03T09:00:00",
TimeZone = "Eastern Standard Time"
},
DueDateTime = new DateTimeTimeZone
{
DateTime = "2016-05-05T16:00:00",
TimeZone = "Eastern Standard Time"
}
};
await graphClient.Me.Outlook.Tasks
.Request()
.Header("Prefer","outlook.timezone=\"Pacific Standard Time\"")
.AddAsync(outlookTask);
const options = {
authProvider,
};
const client = Client.init(options);
const outlookTask = {
subject: 'Shop for children\'s weekend',
startDateTime: {
dateTime: '2016-05-03T09:00:00',
timeZone: 'Eastern Standard Time'
},
dueDateTime: {
dateTime: '2016-05-05T16:00:00',
timeZone: 'Eastern Standard Time'
}
};
await client.api('/me/outlook/tasks')
.version('beta')
.post(outlookTask);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/outlook/tasks"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"outlook.timezone=\"Pacific Standard Time\"" forHTTPHeaderField:@"Prefer"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphOutlookTask *outlookTask = [[MSGraphOutlookTask alloc] init];
[outlookTask setSubject:@"Shop for children's weekend"];
MSGraphDateTimeTimeZone *startDateTime = [[MSGraphDateTimeTimeZone alloc] init];
[startDateTime setDateTime: "2016-05-03T09:00:00"];
[startDateTime setTimeZone:@"Eastern Standard Time"];
[outlookTask setStartDateTime:startDateTime];
MSGraphDateTimeTimeZone *dueDateTime = [[MSGraphDateTimeTimeZone alloc] init];
[dueDateTime setDateTime: "2016-05-05T16:00:00"];
[dueDateTime setTimeZone:@"Eastern Standard Time"];
[outlookTask setDueDateTime:dueDateTime];
NSError *error;
NSData *outlookTaskData = [outlookTask getSerializedDataWithError:&error];
[urlRequest setHTTPBody:outlookTaskData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new HeaderOption("Prefer", "outlook.timezone=\"Pacific Standard Time\""));
OutlookTask outlookTask = new OutlookTask();
outlookTask.subject = "Shop for children's weekend";
DateTimeTimeZone startDateTime = new DateTimeTimeZone();
startDateTime.dateTime = "2016-05-03T09:00:00";
startDateTime.timeZone = "Eastern Standard Time";
outlookTask.startDateTime = startDateTime;
DateTimeTimeZone dueDateTime = new DateTimeTimeZone();
dueDateTime.dateTime = "2016-05-05T16:00:00";
dueDateTime.timeZone = "Eastern Standard Time";
outlookTask.dueDateTime = dueDateTime;
graphClient.me().outlook().tasks()
.buildRequest( requestOptions )
.post(outlookTask);
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewOutlookTask()
subject := "Shop for children's weekend"
requestBody.SetSubject(&subject)
startDateTime := msgraphsdk.NewDateTimeTimeZone()
requestBody.SetStartDateTime(startDateTime)
dateTime := "2016-05-03T09:00:00"
startDateTime.SetDateTime(&dateTime)
timeZone := "Eastern Standard Time"
startDateTime.SetTimeZone(&timeZone)
dueDateTime := msgraphsdk.NewDateTimeTimeZone()
requestBody.SetDueDateTime(dueDateTime)
dateTime := "2016-05-05T16:00:00"
dueDateTime.SetDateTime(&dateTime)
timeZone := "Eastern Standard Time"
dueDateTime.SetTimeZone(&timeZone)
headers := map[string]string{
"Prefer": "outlook.timezone="Pacific Standard Time""
}
options := &msgraphsdk.TasksRequestBuilderPostRequestConfiguration{
Headers: headers,
}
result, err := graphClient.Me().Outlook().Tasks().PostWithRequestConfigurationAndResponseHandler(requestBody, options, nil)
Import-Module Microsoft.Graph.Users
$params = @{
Subject = "Shop for children's weekend"
StartDateTime = @{
DateTime = "2016-05-03T09:00:00"
TimeZone = "Eastern Standard Time"
}
DueDateTime = @{
DateTime = "2016-05-05T16:00:00"
TimeZone = "Eastern Standard Time"
}
}
# A UPN can also be used as -UserId.
New-MgUserOutlookTask -UserId $userId -BodyParameter $params
在请求正文中,提供 outlookTask 对象的 JSON 表示形式。
响应
POST 方法忽略请求正文中 startDateTime 和 dueDateTime 的时间部分,并假定指定时区 (EST 时间始终为午夜) 。
由于标头指定 PST,因此 POST 方法在 PST 中表示响应中所有与 Prefer 日期相关的属性。 特别是,对于 startDateTime 和 dueDateTime 属性,POST 方法将在 EST 中的午夜转换为 PST,在响应中以 PST 格式返回它们。
注意:为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-type: application/json
{
"id": "AAMkADA1MHgwAAA=",
"createdDateTime": "2016-04-22T15:19:18.9526004-07:00",
"lastModifiedDateTime": "2016-04-22T15:19:19.015101-07:00",
"changeKey": "1/KC9Vmu40G3DwB6Lgs7MAAAIW9XXA==",
"categories": [ ],
"assignedTo": null,
"body": {
"contentType": "Text",
"content": ""
},
"completedDateTime": null,
"dueDateTime": {
"dateTime": "2016-05-04T021:00:00.0000000",
"timeZone": "Pacific Standard Time"
},
"hasAttachments":false,
"importance": "normal",
"isReminderOn": false,
"owner": "Administrator",
"parentFolderId": "AQMkADA1MTEgAAAA==",
"recurrence": null,
"reminderDateTime": null,
"sensitivity": "Normal",
"startDateTime": {
"dateTime": "2016-05-02T21:00:00.0000000",
"timeZone": "Pacific Standard Time"
},
"status": "notStarted",
"subject": "Shop for children's weekend"
}