名前空間: microsoft.graph
重要
Microsoft Graph の /beta バージョンの API は変更される可能性があります。 実稼働アプリケーションでこれらの API を使用することは、サポートされていません。 v1.0 で API を使用できるかどうかを確認するには、Version セレクターを使用します。
新しい taskFileAttachment オブジェクトを todoTask に追加します。
この操作では、追加できる添付ファイルのサイズが 3 MB 未満に制限されます。 添付ファイルのサイズが 3 MB を超える場合は、添付ファイル をアップロードするアップロード セッションを作成 します。
この API は、次の国内クラウド展開で使用できます。
| グローバル サービス |
米国政府機関 L4 |
米国政府機関 L5 (DOD) |
21Vianet が運営する中国 |
| ✅ |
✅ |
✅ |
❌ |
アクセス許可
この API の最小特権としてマークされているアクセス許可またはアクセス許可を選択します。
アプリで必要な場合にのみ、より高い特権のアクセス許可またはアクセス許可を使用します。 委任されたアクセス許可とアプリケーションのアクセス許可の詳細については、「アクセス許可の種類」を参照してください。 これらのアクセス許可の詳細については、「アクセス許可のリファレンス」を参照してください。
| アクセス許可の種類 |
最小特権アクセス許可 |
より高い特権のアクセス許可 |
| 委任 (職場または学校のアカウント) |
Tasks.ReadWrite |
注意事項なし。 |
| 委任 (個人用 Microsoft アカウント) |
Tasks.ReadWrite |
注意事項なし。 |
| アプリケーション |
サポートされていません。 |
サポートされていません。 |
HTTP 要求
POST /me/todo/lists/{id}/tasks/{id}/attachments
POST /users/{id}/todo/lists/{id}/tasks/{id}/attachments
| 名前 |
説明 |
| Authorization |
ベアラー {token}。 必須です。
認証と認可についての詳細をご覧ください。 |
| Content-Type |
application/json. 必須です。 |
要求本文
要求本文で、 taskFileAttachment オブジェクトの JSON 表現を指定します。
添付ファイルを作成するときは、 "@odata.type": "#microsoft.graph.taskFileAttachment" と必要なプロパティを含めます。
| プロパティ |
型 |
説明 |
| contentBytes |
Binary |
base64 でエンコードされたファイルの内容。 必須です。 |
| contentType |
String |
添付ファイルのコンテンツ タイプ。 |
| name |
String |
埋め込み添付ファイルを表すアイコンの下に表示されるテキストの名前。 実際のファイル名である必要はありません。 必須です。 |
| size |
Int32 |
添付ファイルのバイト単位のサイズ。 |
応答
成功した場合、このメソッドは応答コード 201 Created と、応答本文に taskFileAttachment オブジェクトを返します。
例
要求
次の例は要求を示しています。
POST https://graph.microsoft.com/beta/me/todo/lists/AAMkpsDRVK=/tasks/AAKdfjhgsjhgJ=/attachments
Content-Type: application/json
{
"@odata.type": "#microsoft.graph.taskFileAttachment",
"name": "smile",
"contentBytes": "a0b1c76de9f7=",
"contentType": "image/gif"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new TaskFileAttachment
{
OdataType = "#microsoft.graph.taskFileAttachment",
Name = "smile",
ContentBytes = Convert.FromBase64String("a0b1c76de9f7="),
ContentType = "image/gif",
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Me.Todo.Lists["{todoTaskList-id}"].Tasks["{todoTask-id}"].Attachments.PostAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewAttachmentBase()
name := "smile"
requestBody.SetName(&name)
contentBytes := []byte("a0b1c76de9f7=")
requestBody.SetContentBytes(&contentBytes)
contentType := "image/gif"
requestBody.SetContentType(&contentType)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
attachments, err := graphClient.Me().Todo().Lists().ByTodoTaskListId("todoTaskList-id").Tasks().ByTodoTaskId("todoTask-id").Attachments().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
TaskFileAttachment attachmentBase = new TaskFileAttachment();
attachmentBase.setOdataType("#microsoft.graph.taskFileAttachment");
attachmentBase.setName("smile");
byte[] contentBytes = Base64.getDecoder().decode("a0b1c76de9f7=");
attachmentBase.setContentBytes(contentBytes);
attachmentBase.setContentType("image/gif");
AttachmentBase result = graphClient.me().todo().lists().byTodoTaskListId("{todoTaskList-id}").tasks().byTodoTaskId("{todoTask-id}").attachments().post(attachmentBase);
const options = {
authProvider,
};
const client = Client.init(options);
const attachmentBase = {
'@odata.type': '#microsoft.graph.taskFileAttachment',
name: 'smile',
contentBytes: 'a0b1c76de9f7=',
contentType: 'image/gif'
};
await client.api('/me/todo/lists/AAMkpsDRVK=/tasks/AAKdfjhgsjhgJ=/attachments')
.version('beta')
.post(attachmentBase);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\TaskFileAttachment;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new TaskFileAttachment();
$requestBody->setOdataType('#microsoft.graph.taskFileAttachment');
$requestBody->setName('smile');
$requestBody->setContentBytes(\GuzzleHttp\Psr7\Utils::streamFor(base64_decode('a0b1c76de9f7=')));
$requestBody->setContentType('image/gif');
$result = $graphServiceClient->me()->todo()->lists()->byTodoTaskListId('todoTaskList-id')->tasks()->byTodoTaskId('todoTask-id')->attachments()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Users
$params = @{
"@odata.type" = "#microsoft.graph.taskFileAttachment"
name = "smile"
contentBytes = "a0b1c76de9f7="
contentType = "image/gif"
}
# A UPN can also be used as -UserId.
New-MgBetaUserTodoListTaskAttachment -UserId $userId -TodoTaskListId $todoTaskListId -TodoTaskId $todoTaskId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.task_file_attachment import TaskFileAttachment
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = TaskFileAttachment(
odata_type = "#microsoft.graph.taskFileAttachment",
name = "smile",
content_bytes = base64.urlsafe_b64decode("a0b1c76de9f7="),
content_type = "image/gif",
)
result = await graph_client.me.todo.lists.by_todo_task_list_id('todoTaskList-id').tasks.by_todo_task_id('todoTask-id').attachments.post(request_body)
応答
次の例は応答を示しています。
注: ここに示す応答オブジェクトは、読みやすさのために短縮されている場合があります。
HTTP/1.1 201 Created
Content-Type: application/json
{
"@odata.type": "#microsoft.graph.taskFileAttachment",
"id": "AAMkADNkN2R",
"lastModifiedDateTime": "2017-01-26T08:48:28Z",
"name": "smile",
"contentType": "image/gif",
"size": 1008
}