| title | Add attachment |
|---|---|
| description | Use this API to create a new Attachment. |
| author | SuryaLashmiS |
| ms.localizationpriority | medium |
| ms.subservice | outlook |
| doc_type | apiPageType |
| ms.date | 06/21/2024 |
Namespace: microsoft.graph
Use this API to create a new Attachment.
An attachment can be one of the following types:
- A file (fileAttachment resource).
- An item (contact, event or message, represented by an itemAttachment resource).
- A link to a file (referenceAttachment resource).
All these types of attachment resources are derived from the attachment resource.
[!INCLUDE national-cloud-support]
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.
[!INCLUDE permissions-table]
POST /me/messages/{id}/attachments
POST /users/{id | userPrincipalName}/messages/{id}/attachments| 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. |
In the request body, supply a JSON representation of Attachment object.
If successful, this method returns 201 Created response code and Attachment object in the response body.
The following example shows a request.
POST https://graph.microsoft.com/v1.0/me/messages/{id}/attachments
Content-type: application/json
{
"@odata.type": "microsoft.graph.fileAttachment",
"name": "name-value",
"contentType": "contentType-value",
"isInline": false,
"contentLocation": "contentLocation-value",
"contentBytes": "base64-contentBytes-value"
}[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
In the request body, supply a JSON representation of attachment object.
The following example shows the response. Note: The response object shown here might be shortened for readability.
HTTP/1.1 201 CreatedPOST https://graph.microsoft.com/v1.0/me/events/{id}/attachments
Content-type: application/json
{
"@odata.type": "#Microsoft.OutlookServices.ItemAttachment",
"name": "name-value",
"item": {
"@odata.type": "microsoft.graph.message"
}
}[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
The following example shows the response. Note: The response object shown here may be truncated for brevity. All of the properties will be returned from an actual call.
HTTP/1.1 201 Created