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/v17.0/me/message_attachments?access_token=<PAGE_ACCESS_TOKEN>

Example Request

Upload from URL

curl --location --request POST 'https://graph.facebook.com/v2.10/me/message_attachments?access_token=<PAGE_ACCESS_TOKEN>' \
--header 'Content-Type: application/json' \
--data-raw '{
  "message":{
    "attachment":{
      "type":"image", 
      "payload":{
        "url":"http://www.messenger-rocks.com/image.jpg",
        "is_reusable": true
      }
    }
  }
}'

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/v17.0/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 --location --request POST 'https://graph.facebook.com/v2.10/me/message_attachments?access_token=<PAGE_ACCESS_TOKEN>' \
--header 'Content-Type: application/json' \
--data-raw '{
  "recipient":{
    "id":"1254459154682919"
  },
  "message":{
    "attachment":{
      "type":"image", 
      "payload":{
        "attachment_id": "1745504518999123"
      }
    }
  }
}'

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

Description of the message to be sent.
Property Type Description

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. Max file size is 8MB for images and 25MB for all other file types (after encoding). A Timeout is set to 75 seconds for videos and 10 seconds for all other file type.

is_reusable

Boolean

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

Error Codes

Error codeSubcodeMessage

100

2018074

Possible invalid ID or you do not own the attachment.

100

2018008

Failed to fetch the file from the url. Check that the URL is valid, with a valid SSL certificate, valid file size, and that the server is responding fast enough to avoid timeouts.

100

2018294

Video upload timed out or video is corrupted. Note that if the video can't be fetched within 75 seconds, it will time out

100

2018047

Upload attachment failure. A common way to trigger this error is that the provided media type does not match type of file provided int the URL