This document explains how to get information about your Messenger and Instagram Messaging conversations. You can get:
This tutorial assumes you have read the Messenger Platform Overview and the Instagram Messaging Overview and implemented the needed components.
You will need:
MESSAGING or MODERATE task on the PageFor Messenger conversations between people and your Page, your app will need:
MESSAGING or MODERATE task on the Pagepages_manage_metadata, pages_read_engagement, and pages_messaging permissionsFor Instagram Messaging conversations between people and your Instagram Professional account, your app will need:
MESSAGING task on the Page linked to your Instagram Business accountinstagram_basic, instagram_manage_messages, and pages_manage_metadata permissionsYou can leverage this API to do inbox syncing on past conversations when an Instagram business account is newly connected to your app.
To get a list of conversations, send a GET request to the /PAGE-ID/conversations endpoint and include the platform parameter set to instagram or messenger.
curl -i -X GET "https://graph.facebook.com/LATEST-API-VERSION/PAGE-ID/conversations
?platform=PLATFORM
&access_token=PAGE-ACCESS-TOKEN"On success, your app will receive a JSON object with a list of IDs for the conversations between you and a person and the most recent time a message was sent.
{
"data":
{
"id": "CONVERSATION-ID-1",
"updated_time": "UNIX-TIMESTAMP"
},
{
"id": "CONVERSATION-ID-2",
"updated_time": "UNIX-TIMESTAMP"
}
...
]
} To get a conversation between your Instagram Professional account or Facebook Page and a specific person, send a GET request to the /PAGE-ID/conversations endpoint with platform parameter and the user_id parameters set to the Instagram-scoped ID or Page-scoped ID for the person.
curl -i -X GET "https://graph.facebook.com/LATEST-API-VERSION/PAGE-ID/conversations
?platform=PLATFORM
&user_id=INSTAGRAM-OR-PAGE-SCOPED-ID
&access_token=PAGE-ACCESS-TOKEN"On success, your app will receive the ID for the conversation.
{
"data": [
{
"id": "CONVERSATION-ID"
},
]
}
To get a list of messages in a conversations, send a GET request to the /CONVERSATION-ID endpoint and include the messages field.
curl -i -X GET "https://graph.facebook.com/LATEST-API-VERSION/CONVERSATION-ID
?fields=messages
&access_token=PAGE-ACCESS-TOKEN"On success, your app will receive a list of message IDs and the time each message was created.
{
"messages": {
"data": [
{
"id": "Message ID-1",
"created_time": "UNIX-TIMESTAMP-MOST-RECENT-MESSAGE"
},
{
"id": "Message ID-2",
"created_time": "UNIX-TIMESTAMP"
},
{
"id": "Message ID-3",
"created_time": "UNIX-TIMESTAMP"
},
...
]
},
"id": "Conversation ID",
}
To get information about a message, such as the sender, receiver, and message content, send a GET request to the /MESSAGE-ID endpoint with the fields you are interested.
The reply_to field will be non-null when a message is a reply and is_self_reply indicates that it is a self reply.
Default fields are id and created_time.
Note: Queries to the /CONVERSATION-ID endpoint will return all message IDs in a conversation. However, you can only get details about the 20 most recent messages in the conversation. If you query a message that is older than the last 20, you will see an error that the message has been deleted.
curl -i -X GET "https://graph.facebook.com/LATEST-API-VERSION/MESSAGE-ID
?fields=id,created_time,from,to,message,reply_to
&access_token=PAGE-ACCESS-TOKEN"On success, your app will receive the following JSON response. In this example a customer sent a plain text message to your Instagram Professional account.
{
"id": "aWdGGiblWZ...",
"created_time": "2022-07-12T19:11:07+0000",
"to": {
"data": [
{
"username": "INSTAGRAM-PROFESSIONAL-ACCOUNT-USERNAME",
"id": "INSTAGRAM-PROFESSIONAL-ACCOUNT-ID"
}
]
},
"from": {
"username": "INSTAGRAM-USERNAME",
"id": "INSTAGRAM-SCOPED-ID"
},
"message": "Hi Kitty!",
"reply_to": {
"mid":"zEspJ9wmRG9…",
"is_self_reply":true
}
}
The Conversations API now supports the is_owner field, allowing your app to determine if it is responsible for responding to a conversation thread.
Why use is_owner?
How to use:
is_owner field in your API call.is_owner is true.Sample Request:
curl -i -X GET "https://graph.facebook.com/LATEST-API-VERSION/conversations?fields=messages,is_owner&access_token=PAGE-ACCESS-TOKEN"
Sample Response:
{
"data": [
{
"messages": {
"data": [
{ "id": "Message ID-1", "created_time": "UNIX-TIMESTAMP" },
{ "id": "Message ID-2", "created_time": "UNIX-TIMESTAMP" }
]
},
"is_owner": true,
"id": "Conversation ID-1"
},
{
"messages": {
"data": [
{ "id": "Message ID-3", "created_time": "UNIX-TIMESTAMP" }
]
},
"is_owner": false,
"id": "Conversation ID-2"
}
]
}Visit our reference for:
to check for the status and outages of Meta business products.
to report bugs and view reported bugs, get help with Ads or Business Manager, and more.
to view more resources for Messenger Platform support.