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 PageFor 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.
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 &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!" }
Visit our reference for: