Bewerken

Delen via


Add attachment

Namespace: microsoft.graph

Add an attachment when creating a group post.

This operation limits the size of the attachment you can add to under 3 MB.

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

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 Not supported.

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. Learn more about authentication and authorization.

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

The following example shows a request that includes a file as an attachment when creating a post.

POST https://graph.microsoft.com/v1.0/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

The following example shows the response.

HTTP/1.1 202 Accpted

Example 2: Include an item attachment

Request

The following example shows a request that includes an event as an attachment when creating a post.

POST https://graph.microsoft.com/v1.0/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

The following example shows the response.

HTTP/1.1 202 Accepted

Example 3: Include a reference attachment

Request

The following example shows a request that includes a reference attachment when creating a post. The attachment points to a folder on OneDrive.

POST https://graph.microsoft.com/v1.0/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

The following example shows the response.

HTTP/1.1 202 Accpted