Attachment Upload API Reference

The Attachment Upload API allows you to upload assets that can be sent in messages at a later time. This allows you to avoid the need to upload commonly used files multiple times. The API supports saving assets from a URL and from your local file system.

You may also use the Send API to simultaneously send a message with an attachment and save the attachment for later use. For more information, see the Send API Reference.

Contents

Request URI

https://graph.facebook.com/v2.6/me/message_attachments?access_token=<PAGE_ACCESS_TOKEN>

Example Request

Upload from URL

curl -X POST -H "Content-Type: application/json" -d '{
  "message":{
    "attachment":{
      "type":"image", 
      "payload":{
        "is_reusable": true,
        "url":"http://www.messenger-rocks.com/image.jpg"
      }
    }
  }
}' "https://graph.facebook.com/v2.6/me/message_attachments?access_token=<PAGE_ACCESS_TOKEN>"

Upload from File

curl  \
  -F 'message={"attachment":{"type":"image", "payload":{"is_reusable":true}}}' \
  -F 'filedata=@/tmp/shirt.png;type=image/png' \
  "https://graph.facebook.com/v2.6/me/message_attachments?access_token=<PAGE_ACCESS_TOKEN>"

Example Response

The reusable attachment ID will be returned:

{
  "attachment_id":"1857777774821032"
}

Attaching Saved Assets

Only attachments that were uploaded with the is_reusable property set to true can be sent to other message recipients.

The Messenger Platform supports saving assets via the Send API and Attachment Upload API. This allows you reuse assets, rather than uploading them every time they are needed.

To attach a saved asset to a message, specify the attachment_id of the asset in the payload.attachment_id property of the message request:

curl -X POST -H "Content-Type: application/json" -d '{
  "recipient":{
    "id":"1254459154682919"
  },
  "message":{
    "attachment":{
      "type":"image", 
      "payload":{
        "attachment_id": "1745504518999123"
      }
    }
  }
}' "https://graph.facebook.com/v2.6/me/messages?access_token=<PAGE_ACCESS_TOKEN>"

Properties

For attachments from a URL, provide the follow properties in the body of the request as a JSON object. For attachments from file, send properties as form data.

message

Property Type Description

message

Object

Description of the message to be sent

message.attachment

Object

An object describing attachments to the message.

message.attachment

Property Type Description

type

String

The type of the attachment. Must be one of the following:

  • image
  • video
  • audio
  • file

payload

Object

payload object that describes the attachment.

message.attachment.payload

Property Type Description

url

String

Optional. URL of the file to upload.

is_reusable

Boolean

Optional. Set to true to make the saved asset sendable to other message recipients. Defaults to false.