This guide shows you how to programmatically create a marketing messages campaign, build the marketing message payload, and send a marketing message on Messenger to a list of subscribers.
The act_<AD_ACCOUNT_ID>/message_campaign endpoint is used to create and manage a marketing campaign that has the same overall objective (marketing messages), targets an audience (subscribers), and defines the budget. Each campaign can have multiple messages targeting specific audiences. For example, a message campaign can have a message that targets new subscribers, a message that targets existing subscribers, and a message that targets everyone.
The act_<AD_ACCOUNT_ID>/messages endpoint is used to create and send marketing messages to subscribers.
This guide assumes that you have created a configuration, invoked the login dialog in your app, tested the login flow and obtained a business' list of subscription tokens.
The Marketing Message API for Messenger is available exclusively to tech providers with an existing app that has successfully completed Meta App Review for the following permissions:
Currently, tech providers can only serve businesses located in the following regions:
|
|
|
|
In addition, messages can be sent to users/subscribers in all regions except:
|
The Marketing Message API for Messenger is only available for Web applications.
You need to create a marketing messages campaign before you can send marketing messages.
Send a POST request to the act_<AD_ACCOUNT_ID>/message_campaign endpoint with the following required parameters:
| Parameter | Description |
|---|---|
| Set to the average amount, in cents, that the business is willing to spend per day.
Either |
| Set to the total amount, in cents, that the business is willing to spend on the campaign.
Either |
| Set to the campaign's name |
| Set to the business' Facebook Page ID that is sending messages |
Formatted for readability.
curl -X POST "https://graph.facebook.com/<API_VERSION>/act_<AD_ACCOUNT_ID>/message_campaign" \
-H "Authorization: Bearer <SYSTEM_USER_ACCESS_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"name": "<MESSAGE_CAMPAIGN_NAME>",
"lifetime_budget": <LIFETIME_BUDGET>,
"page_id": <PAGE_ID>'
}'
On success, your app receives a JSON object containing the message campaign ID, which will be used for sending messages in step 3.
{
"id": "<MESSAGE_CAMPAIGN_ID>"
}
If you are familiar with Meta's Marketing API, this endpoint is similiar to a combination of the campaigns and adsets endpoints.
Guidance for minimum lifetime budget:
min_daily_budget_imp value .min_daily_budget_imp for USD is 100 cents, the minimum lifetime_budget should be $30Learn more about daily and lifetime budgets in the Marketing API documentation.
In this step, we are building the message attachment used when sending a message.
Please refer here for additional information on the different types of templates supported.
For message_payload, please use the payload from above.
curl -X GET \
-H "Authorization: Bearer <SYSTEM_USER_ACCESS_TOKEN>" \
"https://graph.facebook.com/<API_VERSION>/`act_<AD_ACCOUNT_ID>/generatepreviews
?ad_format=MESSENGER_MARKETING_MESSAGES_MEDIA&creative={"marketing_message_structured_spec":{},"object_story_spec":{"page_id":<PAGE_ID>,"link_data":{}}}&message=<MESSAGE_PAYLOAD>"
On success, your app receives a JSON object containing an iframe that, when clicked, will display how your message attachment will look.
{
"data": [
{
"body": "<iframe src=\"https://business.facebook.com/ads/api/preview_iframe.php?d=AQJlIRwQZEB3DV_-9n9Vb7-OXjwuI8tfX-md415ofVW34Lm2fJKx5-e8KinQU7b15t8J5aWQMvd_uv6yZ7XfNtPbJeGWsZoqh7AgvVKKr60cISQMHlRdCOUNKfzSKIBNbkCj-GScUH7XoI16u0LK6EiMgARt9Idn4Ojob58Vtr6ehE6p1VNz3usdjd8OcTf5Tn2oN1s-NDRcSSM_6Dhue7rBif_4upZQ88uUePP6y4WwTYe8N4aVUYphxDT2hnoMoioMX18gzqQ40MibOtvOwbK16EYaajefdzNxi24ptBgXb7B4R_btrz5d3aKeqRN4ZEQhTzYXdmO_I_NZuLUl5n8He0by8mLNQOFNGeMOWvO-H-bOi7vKnubv7fGu3lp0WiAXhY-QTtLASsTU3puD5nbY2-59gND3HKVFnFNtGA95ndRUfrviqlMzDXKNMaRZIX-J0rk-HYPuE9B8z1xV2j-Q&t=AQLPJ9fLVIxT7JDnNo8\" width=\"274\" height=\"213\" scrolling=\"yes\" style=\"border: none;\"><\<iframe>"
}
]
}
When a business’ customer or potential customer opts in to receive marketing messages from the business, your app receives a subscription token ID. Each subscriber is assigned only one subscription token ID, which represents the relationship between the subscriber and the business’s Facebook Page.
If your app has sent marketing messages using the Marketing Messages API in Messenger, all subscription token IDs acquired previously can be used in this new API.
To send a marketing message to a subscriber, make a POSTrequest to the act_<AD_ACCOUNT_ID>/messages endpoint with the following required parameters:
message_id – set to the <MESSAGE_CAMPAIGN_ID> received in step 1messenger_delivery_data.subscription_token – set to the subscription token of the subscribermessage – set to the attachment object built in step 2subscription_token. If sending multiple messages, ensure you delay subsequent messages by at least 12 hours to avoid errors.Formatted for readability.
curl -X POST "https://graph.facebook.com/<API_VERSION>/act_<AD_ACCOUNT_ID>/messages" \
-H "Authorization: Bearer <SYSTEM_USER_ACCESS_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"message_id": "<MESSAGE_CAMPAIGN_ID_FROM_STEP_1>",
"messenger_delivery_data": {
"subscription_token": "<SUBSCRIPTION_TOKEN_ID>"
},
"message": "<MESSAGE_ATTACHMENT_OBJECT_FROM_STEP_2>"
}'
On success, your app receives the following JSON object with success set to true and a marketing_message_tracking_id for tracking this message-sending request in subsequent webhook notifications.
{
"success": true
"marketing_message_tracking_id": "98ecd977-245a-4ec0-a8e0-8b8ecaad8030"
}
If you are familiar with Meta's Marketing API, this endpoint is similiar to the ads endpoint.
Formatted for readability.
curl -X POST "https://graph.facebook.com/<API_VERSION>/act_<AD_ACCOUNT_ID>/messages" \
-H "Authorization: Bearer <SYSTEM_USER_ACCESS_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"message_id": "<MESSAGE_CAMPAIGN_ID_FROM_STEP_1>",
"messenger_delivery_data": {
"subscription_token": "<SUBSCRIPTION_TOKEN_ID>"
},
"message": {
"attachment": {
"type": "template",
"payload": {
"template_type": "generic",
"elements": [
{
"title": "<MESSAGE_TITLE>",
"image_url": "<IMAGE_URL>",
"subtitle": "<ADDITIONAL_MESSAGE_TEXT>",
"default_action": {
"type": "web_url",
"url": "<DEFAULT_URL_TO_OPEN>",
"webview_height_ratio": "<COMPACT_FULL_TALL>"
},
"buttons": [
{
"type": "web_url",
"url": "<BUTTON_URL>",
"title": "<BUTTON_TEXT>"
}
]
}
]
}
}
}
}'
When a marketing message fails to be delivered from a page to a user, a notification is sent to apps subscribed to the marketing_message_delivery_failed event for that page. To receive these notifications through a webhook, follow the setup instructions in the Meta Webhooks for Messenger Platform:
{
"app_id": 12313123123123,
"business_id": 134141414124123,
"page_id": 140984918491243,
"messenger_subscription_token": "12348141984909088",
"timestamp": 41412414141,
"error_message": "Unknown Error",
"message_id": "124141414124"
}
| Property | Description |
|---|---|
| The application ID |
| The end business ID for the page |
| The page ID |
| The |
| Timestamp when the error happened |
| Error message for the marketing message sending failure |
| The ID of the marketing message campaign |
When a marketing message has been sent from the page to a user, a notification is sent to apps subscribed to the marketing_message_echoes event for that page. To receive these notifications through a webhook, follow the setup instructions in the Meta Webhooks for Messenger Platform:
{
"field": "marketing_message_echoes",
"recipient_id": 123123123123
"page_id": 140984918491243,
"app_id": 12313123123123,
"timestamp": 41412414141,
"mid": "mid.$c12312312312312"
"marketing_message_tracking_id": "98ecd977-245a-4ec0-a8e0-8b8ecaad8030"
"messenger_subscription_token": "12348141984909088",
"message_id": "124141414124"
}
| Property | Description |
|---|---|
|
|
| The Page-scoped ID for the person who received a message from your business Note: This field will be invisible if the subscriber is acquired from the Custom Audience API method. |
| The page ID |
| The application ID |
| Timestamp when the error happened |
| ID representing a Messenger's message. Note: This field will be invisible if the subscriber is acquired from the Custom Audience API method. |
| A unique identifier for tracking marketing message requests. |
| The |
| The ID of the marketing message campaign |
When a marketing message has been delivered from the page to a user, a notification is sent to apps subscribed to the marketing_message_deliveries event for that page. To receive these notifications through a webhook, follow the setup instructions in the Meta Webhooks for Messenger Platform:
{
"field": "marketing_message_deliveries",
"recipient_id": 123123123123
"page_id": 140984918491243,
"app_id": 12313123123123,
"timestamp": 41412414141,
"mid": "mid.$c12312312312312"
"marketing_message_tracking_id": "98ecd977-245a-4ec0-a8e0-8b8ecaad8030"
"messenger_subscription_token": "12348141984909088",
"message_id": "124141414124"
}
| Property | Description |
|---|---|
|
|
| The Page-scoped ID for the person who received a message from your business Note: This field will be invisible if the subscriber is acquired from the Custom Audience API method. |
| The page ID |
| The application ID |
| Timestamp when the error happened |
| ID representing a Messenger's message. Note: This field will be invisible if the subscriber is acquired from the Custom Audience API method. |
| A unique identifier for tracking marketing message requests. |
| The |
| The ID of the marketing message campaign |
When a user reads a marketing message, a notification is sent to apps subscribed to the marketing_message_reads event for that page. To receive these notifications through a webhook, follow the setup instructions in the Meta Webhooks for Messenger Platform:
{
"field": "marketing_message_reads",
"recipient_id": 123123123123
"page_id": 140984918491243,
"app_id": 12313123123123,
"timestamp": 41412414141,
"marketing_message_tracking_id": "98ecd977-245a-4ec0-a8e0-8b8ecaad8030"
"messenger_subscription_token": "12348141984909088",
"message_id": "124141414124"
}
| Property | Description |
|---|---|
|
|
| The Page-scoped ID for the person who received a message from your business Note: This field will be invisible if the subscriber is acquired from the Custom Audience API method. |
| The page ID |
| Timestamp when the error happened |
| A unique identifier for tracking marketing message requests. |
| The |
| The ID of the marketing message campaign |
When a user clicks a marketing message, a notification is sent to apps subscribed to the marketing_message_clicks event for that page. To receive these notifications through a webhook, follow the setup instructions in the Meta Webhooks for Messenger Platform:
{
"field": "marketing_message_clicks",
"recipient_id": 123123123123
"page_id": 140984918491243,
"timestamp": 41412414141,
"mid": "mid.$c12312312312312"
"messenger_subscription_token": "12348141984909088",
"message_id": "124141414124"
}
| Property | Description |
|---|---|
|
|
| The Page-scoped ID for the person who received a message from your business Note: This field will be invisible if the subscriber is acquired from the Custom Audience API method. |
| The page ID |
| Timestamp when the error happened |
| ID representing a Messenger's message. Note: This field will be invisible if the subscriber is acquired from the Custom Audience API method. |
| The |
| The ID of the marketing message campaign |
Use Meta's Marketing API <AD_ACCOUNT_ID>/ads endpoint to get a list of all marketing messages campaigns for a business.
Send a GET request to the <AD_ACCOUNT_ID>/ads endpoint and include the fields parameter with the following fields:
adset – Included the following parameters:
name – to get the name of the name of the adsetdaily_budget – The average daily spend over the life of the campaignlifetime_budget – The amount spent over the life of the campaignstart_time – When the campaign started (UNIX timestamp)end_time – When the campaign ended (UNIX timestamp)campaign – include the following parameters:
name – to get the name of the campaignis_message_campaign – to only return marketing message campaignsis_direct_send_campaign – included for marketing message campaignsid – the ID for the message that was sentFormatted for readability.
curl -X GET \
-H "Authorization: Bearer <SYSTEM_USER_ACCESS_TOKEN>" \
"https://graph.facebook.com/<API_VERSION>/act_<AD_ACCOUNT_ID>/ads
?fields=id,
adset{name,daily_budget,lifetime_budget,start_time,end_time},
campaign{name,is_direct_send_campaign,is_message_campaign}"
On success your app receives a JSON object with basic informatiom about the the marketing messaging campaign and message sent during the campaign.
{
"data": [
{
"id": "<MESSAGE_ID>",
"adset": {
"name": "<ADSET_NAME>",
"lifetime_budget": "<LIFETIME_BUDGET>",
"daily_budget": "<DAILY_BUDGET>",
"start_time": "<START_TIME>",
"end_time": "<END_TIME>",
"id": "<ADSET_ID>"
},
"campaign": {
"name": "<MESSAGE_CAMPAIGN_NAME>",
"is_message_campaign": true,
"is_direct_send_campaign": true,
"id": "<MESSAGE_CAMPAIGN_ID>"
}
},
...
]
}
Send a GET request to the <MESSAGE_CAMPAIGN_ID> endpoint to get information about a specific marketing messages campaign. Include the fields parameter with the following fields:
adset – Included the following parameters:
name – to get the name of the name of the adsetdaily_budget – The average daily spend over the life of the campaignlifetime_budget – The amount spent over the life of the campaignstart_time – When the campaign started (UNIX timestamp)end_time – When the campaign ended (UNIX timestamp)campaign{name} – to get the name of the campaigncreative{actor_id} – to get the Facebook Page ID of the businessid – the ID for the messageFormatted for readability.
curl -X GET \
-H "Authorization: Bearer <SYSTEM_USER_ACCESS_TOKEN>" \
"https://graph.facebook.com/<MESSAGE_CAMPAIGN_ID> \
?fields=id,
campaign{name},
creative{actor_id},
adset{name,lifetime_budget,daily_budget,start_time,end_time}"
On success your app receives a JSON object with basic informatiom about the the marketing messaging campaign and message sent during the campaign.
{
"id": "<MESSAGE_CAMPAIGN_ID>"
"campaign": {
"name": "<MESSAGE_CAMPAIGN_NAME>"
},
"adset": {
"lifetime_budget": "<LIFETIME_BUDGET>",
"daily_budget": "<DAILY_BUDGET>",
"start_time": "<START_TIME>",
"end_time": "<END_TIME>",
}
"creative": {
"actor_id": "<PAGE_ID>",
}
}
Send a DELETE request to the /<MESSAGE_CAMPAIGN_ID> endpoint.
Be cautious when deleting campaigns, as this action cannot be undone. Always double-check the message campaign ID before deletion to avoid accidental loss of data.
curl -X DELETE "https://graph.facebook.com/<API_VERSION>/<MESSAGE_CAMPAIGN_ID>" \
-H "Authorization: Bearer <SYSTEM_USER_ACCESS_TOKEN>"
On success, your app receives a JSON object with success set to true.
{
"success": bool
}
You've sent messages, now it's time to measure their performance.