This operation limits the size of the attachment you can add to under 3 MB. If the size of the file attachments is more than 3 MB, create an upload session to upload the attachments.
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions.
Permission type
Permissions (from least to most privileged)
Delegated (work or school account)
Tasks.ReadWrite
Delegated (personal Microsoft account)
Tasks.ReadWrite
Application
Tasks.ReadWrite.All
HTTP request
POST /me/todo/lists/{id}/tasks/{id}/attachments
POST /users/{id}/todo/lists/{id}/tasks/{id}/attachments
Request headers
Name
Description
Authorization
Bearer {token}. Required.
Content-Type
application/json. Required.
Request body
In the request body, supply a JSON representation of the taskFileAttachment object.
When you create a file attachment, include "@odata.type": "#microsoft.graph.taskFileAttachment" and the required properties.
Property
Type
Description
contentBytes
Binary
The base64-encoded contents of the file. Required.
contentType
String
The content type of the attachment.
name
String
The name of the text displayed under the icon that represents the embedded attachment. This does not need to be the actual file name. Required.
size
Int32
The size in bytes of the attachment.
Response
If successful, this method returns a 201 Created response code and a taskFileAttachment object in the response body.
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new AttachmentBase
{
OdataType = "#microsoft.graph.taskFileAttachment",
Name = "smile",
ContentType = "image/gif",
AdditionalData = new Dictionary<string, object>
{
{
"contentBytes" , "a0b1c76de9f7="
},
},
};
var result = await graphClient.Me.Todo.Lists["{todoTaskList-id}"].Tasks["{todoTask-id}"].Attachments.PostAsync(requestBody);
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new AttachmentBase();
$requestBody->set@odatatype('#microsoft.graph.taskFileAttachment');
$requestBody->setName('smile');
$requestBody->setContentType('image/gif');
$additionalData = [
'contentBytes' => 'a0b1c76de9f7=',
];
$requestBody->setAdditionalData($additionalData);
$requestResult = $graphServiceClient->me()->todo()->listsById('todoTaskList-id')->tasksById('todoTask-id')->attachments()->post($requestBody);