Send API Reference

Breaking Change Notice - messaging_type Property Required (Effective May 7, 2018)


As of the release of Messenger Platform v2.2, we are requesting developers to include the messaging_type property in all message sends.

Beginning May 7, 2018, this property will be required for all message sends. After this date, message sends that do not include messaging_type will return an error and not be delivered.

For more information on the messaging_type property, see Messaging Types below.

When your Facebook app is in Development Mode, the Send API will only work for admins, developers and testers of the app.

After your bot is approved for the pages_messaging permission and public, it will work for the general public.

The Send API is the main API used to send messages to users.

Contents

For error codes and their meanings, refer to this page.

Request URI

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

Example Request

curl -X POST -H "Content-Type: application/json" -d '{
  "messaging_type": "<MESSAGING_TYPE>",
  "recipient": {
    "id": "<PSID>"
  },
  "message": {
    "text": "hello, world!"
  }
}' "https://graph.facebook.com/v2.6/me/messages?access_token=<PAGE_ACCESS_TOKEN>"
    

The Graph API version should be set to 2.6 or greater.

Properties

Property Type Description

messaging_type

String

The messaging type of the message being sent.


For supported types and more information, see Sending Messages - Messaging Types

recipient

Object

recipient object

message

Object

message object. message or sender_action must be set.

sender_action

String

Message state to display to the user:

  • typing_on: display the typing bubble
  • typing_off: remove the typing bubble
  • mark_seen: display the confirmation icon

message or sender_action must be set.

notification_type

String

Optional. Push notification type:

  • REGULAR: sound/vibration
  • SILENT_PUSH: on-screen notification only
  • NO_PUSH: no notification

Defaults to REGULAR.

tag

String

Optional. The message tag string. See Message Tags.

recipient

Description of the message recipient. All requests must include one of id, phone_number, or user_ref.

Property Type Description

recipient.id

String

PSID of the message recipient. Either PSID or phone_number must be set.

recipient.phone_number

String

Optional. Phone number of the recipient with the format +1(212)555-2368.


Your bot must be approved for Customer Matching to send messages this way.

recipient.user_ref

String

Optional. user_ref from the checkbox plugin.

recipient.name

Object

Optional. Used only if phone_number is set. Specifies the person's name in the format:


{"first_name":"John", "last_name":"Doe"}

Providing a name increases the odds of a successful match.

The id must be an ID that was retrieved through the Messenger entry points or through the Messenger webhooks (e.g., a person may discover your business in Messenger and start a conversation from there.

These IDs are page-scoped IDs (PSID). This means that the IDs are unique for a given page.

If you have an existing Facebook Login integration, user IDs are app-scoped and will not work with the Messenger platform.

message

Property Type Description

text

String

Message text. Previews will not be shown for the URLs in this field. Use attachment instead. Must be UTF-8 and has a 640 character limit. text or attachment must be set.

attachment

Object

attachment object. Previews the URL. Used to send messages with media or Structured Messages. text or attachment must be set.

quick_replies

Array<quick_reply>

Optional. Array of quick_reply to be sent with messages

metadata

String

Optional. Custom string that is delivered as a message echo. 1000 character limit.

attachment object

The following can be included in the attachment object:

Property Type Description

type

String

Type of attachment, may be image, audio, video, file or template

payload

Object

Payload of attachment

Response

A successful Send API request returns a JSON string containing identifiers for the message and its recipient.

Example

{
  "recipient_id": "1254477777772919",
  "message_id": "mid.$cAAJsujCd2ORj_1qmrFdzhVa-4cvO"
}  

Properties

Property Name Description

recipient_id

Unique ID for the user

message_id

Unique ID for the message

Rate Limits

Messenger Platform supports a high rate of calls to the Send API.

However, you should architect your system such that you distribute any sudden high amounts of load over time and are able to control your throughput should you hit our rate limits.

Rate limits are in place to prevent malicious behavior and poor user experiences.

Be sure to catch any errors returned by the Send API including the one indicating that you've reached the rate limit.