Add attachment

Important

APIs under the /beta version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported.

Add an attachment when creating a group post.

Since there is currently a limit of 4MB on the total size of each REST request, this limits the size of the attachment you can add to under 4MB.

An attachment can be one of the following types:

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

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) Group.ReadWrite.All
Delegated (personal Microsoft account) Not supported.
Application Group.ReadWrite.All

HTTP request

Include an attachment when creating a post in a conversationThread of a group. Specifying the parent conversation is optional.

POST /groups/{id}/threads/{id}/reply
POST /groups/{id}/conversations/{id}/threads/{id}/reply

Request headers

Header Value
Authorization Bearer {token}. Required.

Request body

In the request body, provide a JSON object that includes a post parameter.

Parameter Type Description
post post The new post that is being replied with, which includes one or more attachments in an attachment collection.

Response

If successful, this method returns 202 Accepted response code. It does not return a response body.

Examples

Example 1: Include a file attachment

Request

Here is an example of a request that includes a file as an attachment when creating a post.

POST https://graph.microsoft.com/beta/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"
    } ]
  }
}

Response

Here is an example of the response.

HTTP/1.1 202 Accpted

Example 2: Include an item attachment

Request

Here is an example of a request that includes an event as an attachment when creating a post.

POST https://graph.microsoft.com/beta/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"
          }
      }
    } ]
  }
}

Response

Here is an example of the response.

HTTP/1.1 202 Accepted

Example 3: Include a reference attachment

Request

Here is an example of a request that includes a reference attachment when creating a post. The attachment points to a folder on OneDrive.

POST https://graph.microsoft.com/beta/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"
    } ]
  }
}

Response

Here is an example of the response.

HTTP/1.1 202 Accpted