添付ファイルを追加
[アーティクル]
07/09/2022
3 人の共同作成者
この記事の内容
名前空間: microsoft.graph
グループ投稿を作成するときに 添付ファイル を追加します。
この操作では、追加できる添付ファイルのサイズを 4 MB 未満に制限します。
添付ファイルには、次の種類のいずれかを指定できます。
これらの添付ファイル リソースのすべての種類は、attachment リソースから派生します。
アクセス許可
この API を呼び出すには、次のいずれかのアクセス許可が必要です。アクセス許可の選択方法などの詳細については、「アクセス許可 」を参照してください。
アクセス許可の種類
アクセス許可 (特権の小さいものから大きいものへ)
委任 (職場または学校のアカウント)
Group.ReadWrite.All
委任 (個人用 Microsoft アカウント)
サポートされていません。
アプリケーション
サポートされていません。
HTTP 要求
グループのスレッドスレッド で投稿 を作成するときに添付ファイルを含めます。 親 会話 の指定は省略可能です。
POST /groups/{id}/threads/{id}/reply
POST /groups/{id}/conversations/{id}/threads/{id}/reply
ヘッダー
値
Authorization
ベアラー {token}。必須。
要求本文
要求本文で、 post パラメーターを含む JSON オブジェクトを指定します。
パラメーター
型
説明
post
post
返信される新しい投稿。添付ファイル コレクションに 1 つ以上の添付 ファイル が含まれます。
応答
成功した場合、このメソッドは 202 Accepted 応答コードを返します。応答本文は返されません。
例
例 1: 添付ファイルを含める
要求
投稿の作成時に添付ファイルとしてファイルを含む要求の例を次に示します。
POST https://graph.microsoft.com/v1.0/groups/1848753d-185d-4c08-a4e4-6ee40521d115/threads/AAQkADJUdfolA==/reply
Content-type: application/json
{
"post": {
"body": {
"contentType": "text",
"content": "Which quarter does that file cover? See my attachment."
},
"attachments": [{
"@odata.type": "#microsoft.graph.fileAttachment",
"name": "Another file as attachment",
"contentBytes": "VGhpcyBpcyBhIGZpbGUgdG8gYmUgYXR0YWNoZWQu"
} ]
}
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var post = new Post
{
Body = new ItemBody
{
ContentType = BodyType.Text,
Content = "Which quarter does that file cover? See my attachment."
},
Attachments = new PostAttachmentsCollectionPage()
{
new FileAttachment
{
Name = "Another file as attachment",
ContentBytes = Encoding.ASCII.GetBytes("VGhpcyBpcyBhIGZpbGUgdG8gYmUgYXR0YWNoZWQu")
}
}
};
await graphClient.Groups["{group-id}"].Threads["{conversationThread-id}"]
.Reply(post)
.Request()
.PostAsync();
SDK をプロジェクトに追加し、authProvider インスタンスを作成する 方法の詳細については、SDK のドキュメントを参照してください 。
const options = {
authProvider,
};
const client = Client.init(options);
const reply = {
post: {
body: {
contentType: 'text',
content: 'Which quarter does that file cover? See my attachment.'
},
attachments: [{
'@odata.type': '#microsoft.graph.fileAttachment',
name: 'Another file as attachment',
contentBytes: 'VGhpcyBpcyBhIGZpbGUgdG8gYmUgYXR0YWNoZWQu'
} ]
}
};
await client.api('/groups/1848753d-185d-4c08-a4e4-6ee40521d115/threads/AAQkADJUdfolA==/reply')
.post(reply);
SDK をプロジェクトに追加し、authProvider インスタンスを作成する 方法の詳細については、SDK のドキュメントを参照してください 。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/groups/1848753d-185d-4c08-a4e4-6ee40521d115/threads/AAQkADJUdfolA==/reply"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSMutableDictionary *payloadDictionary = [[NSMutableDictionary alloc] init];
MSGraphPost *post = [[MSGraphPost alloc] init];
MSGraphItemBody *body = [[MSGraphItemBody alloc] init];
[body setContentType: [MSGraphBodyType text]];
[body setContent:@"Which quarter does that file cover? See my attachment."];
[post setBody:body];
NSMutableArray *attachmentsList = [[NSMutableArray alloc] init];
MSGraphAttachment *attachments = [[MSGraphAttachment alloc] init];
[attachments setName:@"Another file as attachment"];
[attachments setContentBytes:@"VGhpcyBpcyBhIGZpbGUgdG8gYmUgYXR0YWNoZWQu"];
[attachmentsList addObject: attachments];
[post setAttachments:attachmentsList];
payloadDictionary[@"post"] = post;
NSData *data = [NSJSONSerialization dataWithJSONObject:payloadDictionary options:kNilOptions error:&error];
[urlRequest setHTTPBody:data];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
SDK をプロジェクトに追加し、authProvider インスタンスを作成する 方法の詳細については、SDK のドキュメントを参照してください 。
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Post post = new Post();
ItemBody body = new ItemBody();
body.contentType = BodyType.TEXT;
body.content = "Which quarter does that file cover? See my attachment.";
post.body = body;
LinkedList<Attachment> attachmentsList = new LinkedList<Attachment>();
FileAttachment attachments = new FileAttachment();
attachments.name = "Another file as attachment";
attachments.contentBytes = Base64.getDecoder().decode("VGhpcyBpcyBhIGZpbGUgdG8gYmUgYXR0YWNoZWQu");
attachmentsList.add(attachments);
AttachmentCollectionResponse attachmentCollectionResponse = new AttachmentCollectionResponse();
attachmentCollectionResponse.value = attachmentsList;
AttachmentCollectionPage attachmentCollectionPage = new AttachmentCollectionPage(attachmentCollectionResponse, null);
post.attachments = attachmentCollectionPage;
graphClient.groups("1848753d-185d-4c08-a4e4-6ee40521d115").threads("AAQkADJUdfolA==")
.reply(ConversationThreadReplyParameterSet
.newBuilder()
.withPost(post)
.build())
.buildRequest()
.post();
SDK をプロジェクトに追加し、authProvider インスタンスを作成する 方法の詳細については、SDK のドキュメントを参照してください 。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewPostRequestBody()
post := msgraphsdk.NewPost()
requestBody.SetPost(post)
body := msgraphsdk.NewItemBody()
post.SetBody(body)
contentType := "text"
body.SetContentType(&contentType)
content := "Which quarter does that file cover? See my attachment."
body.SetContent(&content)
post.SetAttachments( []Attachment {
msgraphsdk.NewAttachment(),
name := "Another file as attachment"
SetName(&name)
SetAdditionalData(map[string]interface{}{
"@odata.type": "#microsoft.graph.fileAttachment",
"contentBytes": "VGhpcyBpcyBhIGZpbGUgdG8gYmUgYXR0YWNoZWQu",
}
}
groupId := "group-id"
conversationThreadId := "conversationThread-id"
graphClient.GroupsById(&groupId).ThreadsById(&conversationThreadId).Reply(group-id, conversationThread-id).Post(requestBody)
SDK をプロジェクトに追加し、authProvider インスタンスを作成する 方法の詳細については、SDK のドキュメントを参照してください 。
Import-Module Microsoft.Graph.Groups
$params = @{
Post = @{
Body = @{
ContentType = "text"
Content = "Which quarter does that file cover? See my attachment."
}
Attachments = @(
@{
"@odata.type" = "#microsoft.graph.fileAttachment"
Name = "Another file as attachment"
ContentBytes = "VGhpcyBpcyBhIGZpbGUgdG8gYmUgYXR0YWNoZWQu"
}
)
}
}
Invoke-MgReplyGroupThread -GroupId $groupId -ConversationThreadId $conversationThreadId -BodyParameter $params
SDK をプロジェクトに追加し、authProvider インスタンスを作成する 方法の詳細については、SDK のドキュメントを参照してください 。
応答
以下は、応答の例です。
HTTP/1.1 202 Accpted
例 2: アイテムの添付ファイルを含める
要求
投稿の作成時に添付ファイルとしてイベントを含む要求の例を次に示します。
POST https://graph.microsoft.com/v1.0/groups/1848753d-185d-4c08-a4e4-6ee40521d115/threads/AAQkADJUdfolA==/reply
Content-type: application/json
{
"post": {
"body": {
"contentType": "text",
"content": "I attached an event."
},
"attachments": [{
"@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": "2019-12-02T18:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2019-12-02T19:00:00",
"timeZone": "Pacific Standard Time"
}
}
} ]
}
}
応答
以下は、応答の例です。
HTTP/1.1 202 Accepted
例 3: 参照添付ファイルを含める
要求
投稿の作成時に参照添付ファイルを含む要求の例を次に示します。
添付ファイルは OneDrive 上のフォルダーを指しています。
POST https://graph.microsoft.com/v1.0/groups/1848753d-185d-4c08-a4e4-6ee40521d115/threads/AAQkADJUdfolA==/reply
Content-type: application/json
{
"post": {
"body": {
"contentType": "text",
"content": "I attached a reference to a file on OneDrive."
},
"attachments": [{
"@odata.type": "#microsoft.graph.referenceAttachment",
"name": "Personal pictures",
"sourceUrl": "https://contoso.com/personal/mario_contoso_net/Documents/Pics",
"providerType": "oneDriveConsumer",
"permission": "Edit",
"isFolder": "True"
} ]
}
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var post = new Post
{
Body = new ItemBody
{
ContentType = BodyType.Text,
Content = "I attached an event."
},
Attachments = new PostAttachmentsCollectionPage()
{
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 = "2019-12-02T18:00:00",
TimeZone = "Pacific Standard Time"
},
End = new DateTimeTimeZone
{
DateTime = "2019-12-02T19:00:00",
TimeZone = "Pacific Standard Time"
}
}
}
}
};
await graphClient.Groups["{group-id}"].Threads["{conversationThread-id}"]
.Reply(post)
.Request()
.PostAsync();
SDK をプロジェクトに追加し、authProvider インスタンスを作成する 方法の詳細については、SDK のドキュメントを参照してください 。
const options = {
authProvider,
};
const client = Client.init(options);
const reply = {
post: {
body: {
contentType: 'text',
content: 'I attached a reference to a file on OneDrive.'
},
attachments: [{
'@odata.type': '#microsoft.graph.referenceAttachment',
name: 'Personal pictures',
sourceUrl: 'https://contoso.com/personal/mario_contoso_net/Documents/Pics',
providerType: 'oneDriveConsumer',
permission: 'Edit',
isFolder: 'True'
} ]
}
};
await client.api('/groups/1848753d-185d-4c08-a4e4-6ee40521d115/threads/AAQkADJUdfolA==/reply')
.post(reply);
SDK をプロジェクトに追加し、authProvider インスタンスを作成する 方法の詳細については、SDK のドキュメントを参照してください 。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/groups/1848753d-185d-4c08-a4e4-6ee40521d115/threads/AAQkADJUdfolA==/reply"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSMutableDictionary *payloadDictionary = [[NSMutableDictionary alloc] init];
MSGraphPost *post = [[MSGraphPost alloc] init];
MSGraphItemBody *body = [[MSGraphItemBody alloc] init];
[body setContentType: [MSGraphBodyType text]];
[body setContent:@"I attached a reference to a file on OneDrive."];
[post setBody:body];
NSMutableArray *attachmentsList = [[NSMutableArray alloc] init];
MSGraphAttachment *attachments = [[MSGraphAttachment alloc] init];
[attachments setName:@"Personal pictures"];
[attachments setSourceUrl:@"https://contoso.com/personal/mario_contoso_net/Documents/Pics"];
[attachments setProviderType:@"oneDriveConsumer"];
[attachments setPermission:@"Edit"];
[attachments setIsFolder:@"True"];
[attachmentsList addObject: attachments];
[post setAttachments:attachmentsList];
payloadDictionary[@"post"] = post;
NSData *data = [NSJSONSerialization dataWithJSONObject:payloadDictionary options:kNilOptions error:&error];
[urlRequest setHTTPBody:data];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
SDK をプロジェクトに追加し、authProvider インスタンスを作成する 方法の詳細については、SDK のドキュメントを参照してください 。
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Post post = new Post();
ItemBody body = new ItemBody();
body.contentType = BodyType.TEXT;
body.content = "I attached an event.";
post.body = body;
LinkedList<Attachment> attachmentsList = new LinkedList<Attachment>();
ItemAttachment attachments = new ItemAttachment();
attachments.name = "Holiday event";
Event item = new Event();
item.subject = "Discuss gifts for children";
ItemBody body1 = new ItemBody();
body1.contentType = BodyType.HTML;
body1.content = "Let's look for funding!";
item.body = body1;
DateTimeTimeZone start = new DateTimeTimeZone();
start.dateTime = "2019-12-02T18:00:00";
start.timeZone = "Pacific Standard Time";
item.start = start;
DateTimeTimeZone end = new DateTimeTimeZone();
end.dateTime = "2019-12-02T19:00:00";
end.timeZone = "Pacific Standard Time";
item.end = end;
attachments.item = item;
attachmentsList.add(attachments);
AttachmentCollectionResponse attachmentCollectionResponse = new AttachmentCollectionResponse();
attachmentCollectionResponse.value = attachmentsList;
AttachmentCollectionPage attachmentCollectionPage = new AttachmentCollectionPage(attachmentCollectionResponse, null);
post.attachments = attachmentCollectionPage;
graphClient.groups("1848753d-185d-4c08-a4e4-6ee40521d115").threads("AAQkADJUdfolA==")
.reply(ConversationThreadReplyParameterSet
.newBuilder()
.withPost(post)
.build())
.buildRequest()
.post();
SDK をプロジェクトに追加し、authProvider インスタンスを作成する 方法の詳細については、SDK のドキュメントを参照してください 。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewPostRequestBody()
post := msgraphsdk.NewPost()
requestBody.SetPost(post)
body := msgraphsdk.NewItemBody()
post.SetBody(body)
contentType := "text"
body.SetContentType(&contentType)
content := "I attached a reference to a file on OneDrive."
body.SetContent(&content)
post.SetAttachments( []Attachment {
msgraphsdk.NewAttachment(),
name := "Personal pictures"
SetName(&name)
SetAdditionalData(map[string]interface{}{
"@odata.type": "#microsoft.graph.referenceAttachment",
"sourceUrl": "https://contoso.com/personal/mario_contoso_net/Documents/Pics",
"providerType": "oneDriveConsumer",
"permission": "Edit",
"isFolder": "True",
}
}
groupId := "group-id"
conversationThreadId := "conversationThread-id"
graphClient.GroupsById(&groupId).ThreadsById(&conversationThreadId).Reply(group-id, conversationThread-id).Post(requestBody)
SDK をプロジェクトに追加し、authProvider インスタンスを作成する 方法の詳細については、SDK のドキュメントを参照してください 。
Import-Module Microsoft.Graph.Groups
$params = @{
Post = @{
Body = @{
ContentType = "text"
Content = "I attached a reference to a file on OneDrive."
}
Attachments = @(
@{
"@odata.type" = "#microsoft.graph.referenceAttachment"
Name = "Personal pictures"
SourceUrl = "https://contoso.com/personal/mario_contoso_net/Documents/Pics"
ProviderType = "oneDriveConsumer"
Permission = "Edit"
IsFolder = "True"
}
)
}
}
Invoke-MgReplyGroupThread -GroupId $groupId -ConversationThreadId $conversationThreadId -BodyParameter $params
SDK をプロジェクトに追加し、authProvider インスタンスを作成する 方法の詳細については、SDK のドキュメントを参照してください 。
応答
以下は、応答の例です。
HTTP/1.1 202 Accpted