Retrieve chats & messages
Learn how to retrieve Instagram chats and messages with Unipile API.
Get individual and group chats
All conversations are grouped into a single inbox. To fetch them, use the List all Chats method.
You can apply filters such as archive status or unread status when they are relevant to your workflow.
const { data, error } = await messagingApi.getChatsList({
path: {
account_id: "acc_123456789",
},
query: {
limit: 20,
},
});chats = messaging_api.get_chats_list(
"acc_123456789",
limit=20,
)To get a single chat, use Get a Chat.
const { data, error } = await messagingApi.getChat({
path: {
account_id: "acc_123456789",
chat_id: "chat_id",
},
});chat = messaging_api.get_chat("chat_id", "acc_123456789")Get Messages
To list the messages of a chat, use List all Chat Messages and provide the chat ID.
const { data, error } = await messagingApi.getMessagesList({
path: {
account_id: "acc_123456789",
chat_id: "chat_id",
},
query: {
limit: 20,
},
});messages = messaging_api.get_messages_list(
"chat_id",
"acc_123456789",
limit=20,
)curl --request GET \
--url https://api.unipile.com/v2/account_id/chats/chat_id/messages \
--header 'accept: application/json'To retrieve a single message, use Get a Message and provide the chat ID together with the message ID.
const { data, error } = await messagingApi.getMessage({
path: {
account_id: "acc_123456789",
chat_id: "chat_id",
message_id: "message_id",
},
});message = messaging_api.get_message(
"chat_id",
"message_id",
"acc_123456789",
)curl --request GET \
--url https://api.unipile.com/v2/account_id/chats/chat_id/messages/message_id \
--header 'accept: application/json'Download attachments
Use Get a Message Attachment to stream media returned by Instagram.
Unipile exposes the attachment metadata in message payloads, then proxies the download for you.
const { data, error } = await messagingApi.getAttachment({
path: {
account_id: "acc_123456789",
chat_id: "chat_id",
message_id: "message_id",
attachment_id: "attachment_id",
},
});attachment = messaging_api.get_attachment(
"chat_id",
"message_id",
"attachment_id",
"acc_123456789",
)curl --request GET \
--url https://api.unipile.com/v2/account_id/chats/chat_id/messages/message_id/attachments/attachment_id \
--header 'accept: application/json'Realtime events
To receive messaging activity in real time, configure a webhook and listen to:
message.newmessage.updatemessage.deletemessage.reaction.new
This allows your integration to stay synchronized when messages are created, edited, deleted, or reacted to from other devices.
Limitations
Instagram-specific unsupported messaging features are documented in Unsupported features.
Updated about 1 month ago