Add attachment

Namespace: microsoft.graph

Important

APIs under the /beta version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. To determine whether an API is available in v1.0, use the Version selector.

Use this API to create a new Attachment.

An attachment can be one of the following types:

All these types of attachment resources are derived from the attachment resource.

This API is available in the following national cloud deployments.

Global service US Government L4 US Government L5 (DOD) China operated by 21Vianet

Permissions

Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.

Permission type Least privileged permissions Higher privileged permissions
Delegated (work or school account) Mail.ReadWrite Not available.
Delegated (personal Microsoft account) Mail.ReadWrite Not available.
Application Mail.ReadWrite Not available.

HTTP request

POST /me/messages/{id}/attachments
POST /users/{id|userPrincipalName}/messages/{id}/attachments

Request headers

Name Type Description
Authorization string Bearer {token}. Required. Learn more about authentication and authorization.
Content-Type string Nature of the data in the body of an entity. Required.

Request body

In the request body, supply a JSON representation of Attachment object.

Response

If successful, this method returns 201 Created response code and Attachment object in the response body.

Example (file attachment)

Request

The following example shows a request.

POST https://graph.microsoft.com/beta/me/messages/{id}/attachments
Content-type: application/json

{
  "@odata.type": "#Microsoft.OutlookServices.FileAttachment",
  "name": "name-value",
  "contentType": "contentType-value",
  "isInline": false,
  "contentLocation": "contentLocation-value",
  "contentBytes": "contentBytes-value"
}
Response

The following example shows the response. Note: The response object shown here might be shortened for readability.

HTTP 201 Created

Example (item attachment)

Request
POST https://graph.microsoft.com/beta/me/events/{id}/attachments
Content-type: application/json

{
  "@odata.type": "#Microsoft.OutlookServices.ItemAttachment",
  "name": "name-value",
  "item": {
    "@odata.type": "microsoft.graph.message"
  }
}
Response

The following example shows the response. Note: The response object shown here might be shortened for readability.

HTTP 201 Created