创建 (已弃)
本文内容
命名空间:microsoft.graph
重要
Microsoft Graph版本下的 /beta API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
使用此 API 将附件 添加到 outlookTask 。 附件可以是fileAttachment (类型的文件,) Outlook itemAttachment (itemAttachment ) 。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限 。
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
Tasks.ReadWrite
委派(个人 Microsoft 帐户)
Tasks.ReadWrite
应用程序
不支持。
HTTP 请求
POST /me/outlook/tasks/{id}/attachments
POST /users/{id|userPrincipalName}/outlook/tasks/{id}/attachments
名称
说明
Authorization
Bearer {token}。必需。
Content-Type
表示实体正文中数据类型的字符串。 必需。
请求正文
在请求正文中,提供 attachment 对象的 JSON 表示形式。
响应
如果成功,此方法在响应正文中返回 201 Created 响应代码和 attachment 对象。
示例
示例 1:添加文件附件
请求
下面是一个请求示例。
POST https://graph.microsoft.com/beta/me/outlook/tasks/AAMkADAAAANXbdnAAA=/attachments
Content-type: application/json
{
"@odata.type": "#microsoft.graph.fileAttachment",
"name": "menu.txt",
"contentBytes": "bWFjIGFuZCBjaGVlc2UgdG9kYXk="
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var attachment = new FileAttachment
{
Name = "menu.txt",
ContentBytes = Convert.FromBase64String("bWFjIGFuZCBjaGVlc2UgdG9kYXk=")
};
await graphClient.Me.Outlook.Tasks["{outlookTask-id}"].Attachments
.Request()
.AddAsync(attachment);
const options = {
authProvider,
};
const client = Client.init(options);
const attachment = {
'@odata.type': '#microsoft.graph.fileAttachment',
name: 'menu.txt',
contentBytes: 'bWFjIGFuZCBjaGVlc2UgdG9kYXk='
};
await client.api('/me/outlook/tasks/AAMkADAAAANXbdnAAA=/attachments')
.version('beta')
.post(attachment);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/outlook/tasks/AAMkADAAAANXbdnAAA=/attachments"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphAttachment *attachment = [[MSGraphAttachment alloc] init];
[attachment setName:@"menu.txt"];
[attachment setContentBytes:@"bWFjIGFuZCBjaGVlc2UgdG9kYXk="];
NSError *error;
NSData *attachmentData = [attachment getSerializedDataWithError:&error];
[urlRequest setHTTPBody:attachmentData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
FileAttachment attachment = new FileAttachment();
attachment.name = "menu.txt";
attachment.contentBytes = Base64.getDecoder().decode("bWFjIGFuZCBjaGVlc2UgdG9kYXk=");
graphClient.me().outlook().tasks("AAMkADAAAANXbdnAAA=").attachments()
.buildRequest()
.post(attachment);
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewAttachment()
name := "menu.txt"
requestBody.SetName(&name)
requestBody.SetAdditionalData(map[string]interface{}{
"@odata.type": "#microsoft.graph.fileAttachment",
"contentBytes": "bWFjIGFuZCBjaGVlc2UgdG9kYXk=",
}
outlookTaskId := "outlookTask-id"
result, err := graphClient.Me().Outlook().TasksById(&outlookTaskId).Attachments().Post(requestBody)
Import-Module Microsoft.Graph.Users
$params = @{
"@odata.type" = "#microsoft.graph.fileAttachment"
Name = "menu.txt"
ContentBytes = "bWFjIGFuZCBjaGVlc2UgdG9kYXk="
}
# A UPN can also be used as -UserId.
New-MgUserOutlookTaskAttachment -UserId $userId -OutlookTaskId $outlookTaskId -BodyParameter $params
响应
这是一个示例响应。注意:为提高可读性,可能缩短了此处显示的响应对象。
HTTP 201 Created
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#users('64339082-ed84-4b0b-b4ab-004ae54f3747')/outlook/tasks('AAMkADAAAANXbdnAAA%3D')/attachments/$entity",
"@odata.type": "#microsoft.graph.fileAttachment",
"@odata.mediaContentType": "text/plain",
"id": "AAMkADAAAANXbdnAAABEgAQAKQF4_X0QwVHpmAmxUgHN_Q=",
"lastModifiedDateTime": "2020-01-07T22:13:30Z",
"name": "menu.txt",
"contentType": "text/plain",
"size": 178,
"isInline": false,
"contentId": null,
"contentLocation": null,
"contentBytes": "bWFjIGFuZCBjaGVlc2UgdG9kYXk="
}
示例 2:添加项目附件
请求
下面将一个事件附加到另一个事件作为项目附件的示例。
POST https://graph.microsoft.com/beta/me/outlook/tasks/AAMkADAAAANXbdnAAA=/attachments
Content-type: application/json
{
"@odata.type": "#microsoft.graph.itemAttachment",
"name": "Holiday event",
"item": {
"@odata.type": "microsoft.graph.event",
"subject": "Discuss gifts for children",
"body": {
"contentType": "HTML",
"content": "Let's look for funding!"
},
"start": {
"dateTime": "2020-01-12T18:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2020-01-12T19:00:00",
"timeZone": "Pacific Standard Time"
}
}
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var attachment = new ItemAttachment
{
Name = "Holiday event",
Item = new Event
{
Subject = "Discuss gifts for children",
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "Let's look for funding!"
},
Start = new DateTimeTimeZone
{
DateTime = "2020-01-12T18:00:00",
TimeZone = "Pacific Standard Time"
},
End = new DateTimeTimeZone
{
DateTime = "2020-01-12T19:00:00",
TimeZone = "Pacific Standard Time"
}
}
};
await graphClient.Me.Outlook.Tasks["{outlookTask-id}"].Attachments
.Request()
.AddAsync(attachment);
const options = {
authProvider,
};
const client = Client.init(options);
const attachment = {
'@odata.type': '#microsoft.graph.itemAttachment',
name: 'Holiday event',
item: {
'@odata.type': 'microsoft.graph.event',
subject: 'Discuss gifts for children',
body: {
contentType: 'HTML',
content: 'Let\'s look for funding!'
},
start: {
dateTime: '2020-01-12T18:00:00',
timeZone: 'Pacific Standard Time'
},
end: {
dateTime: '2020-01-12T19:00:00',
timeZone: 'Pacific Standard Time'
}
}
};
await client.api('/me/outlook/tasks/AAMkADAAAANXbdnAAA=/attachments')
.version('beta')
.post(attachment);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/outlook/tasks/AAMkADAAAANXbdnAAA=/attachments"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphAttachment *attachment = [[MSGraphAttachment alloc] init];
[attachment setName:@"Holiday event"];
MSGraphOutlookItem *item = [[MSGraphOutlookItem alloc] init];
[item setSubject:@"Discuss gifts for children"];
MSGraphItemBody *body = [[MSGraphItemBody alloc] init];
[body setContentType: [MSGraphBodyType html]];
[body setContent:@"Let's look for funding!"];
[item setBody:body];
MSGraphDateTimeTimeZone *start = [[MSGraphDateTimeTimeZone alloc] init];
[start setDateTime: "2020-01-12T18:00:00"];
[start setTimeZone:@"Pacific Standard Time"];
[item setStart:start];
MSGraphDateTimeTimeZone *end = [[MSGraphDateTimeTimeZone alloc] init];
[end setDateTime: "2020-01-12T19:00:00"];
[end setTimeZone:@"Pacific Standard Time"];
[item setEnd:end];
[attachment setItem:item];
NSError *error;
NSData *attachmentData = [attachment getSerializedDataWithError:&error];
[urlRequest setHTTPBody:attachmentData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
ItemAttachment attachment = new ItemAttachment();
attachment.name = "Holiday event";
Event item = new Event();
item.subject = "Discuss gifts for children";
ItemBody body = new ItemBody();
body.contentType = BodyType.HTML;
body.content = "Let's look for funding!";
item.body = body;
DateTimeTimeZone start = new DateTimeTimeZone();
start.dateTime = "2020-01-12T18:00:00";
start.timeZone = "Pacific Standard Time";
item.start = start;
DateTimeTimeZone end = new DateTimeTimeZone();
end.dateTime = "2020-01-12T19:00:00";
end.timeZone = "Pacific Standard Time";
item.end = end;
attachment.item = item;
graphClient.me().outlook().tasks("AAMkADAAAANXbdnAAA=").attachments()
.buildRequest()
.post(attachment);
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewAttachment()
name := "Holiday event"
requestBody.SetName(&name)
requestBody.SetAdditionalData(map[string]interface{}{
"@odata.type": "#microsoft.graph.itemAttachment",
}
outlookTaskId := "outlookTask-id"
result, err := graphClient.Me().Outlook().TasksById(&outlookTaskId).Attachments().Post(requestBody)
Import-Module Microsoft.Graph.Users
$params = @{
"@odata.type" = "#microsoft.graph.itemAttachment"
Name = "Holiday event"
Item = @{
"@odata.type" = "microsoft.graph.event"
Subject = "Discuss gifts for children"
}
}
# A UPN can also be used as -UserId.
New-MgUserOutlookTaskAttachment -UserId $userId -OutlookTaskId $outlookTaskId -BodyParameter $params
响应
这是一个示例响应。注意:为提高可读性,可能缩短了此处显示的响应对象。
HTTP 201 Created
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#users('64339082-ed84-4b0b-b4ab-004ae54f3747')/outlook/tasks('AAMkADAAAANXbdnAAA%3D')/attachments/$entity",
"@odata.type": "#microsoft.graph.itemAttachment",
"id": "AAMkADAAAANXbdnAAABEgAQANgBvaZHiKVMskpdj1k9KEQ=",
"lastModifiedDateTime": "2020-01-07T22:18:11Z",
"name": "Holiday event",
"contentType": null,
"size": 2067,
"isInline": false
}