Chats And Messages
The Instagram inbox in Unipile's Chat, Message and ChatAttendee objects: listing, reading, sending, starting a chat, files, reactions, and when Instagram shows Seen.
Early access. Tell us what you're building and we'll set you up. Contact us
The account's Instagram inbox (its direct messages), in Unipile's Chat,
Message and ChatAttendee objects. Every call names the account with
account_id, in the query for reads and in the body for writes.
Chat And Message IDs#
- A chat's id is Instagram's own: the number in
instagram.com/direct/t/<id>/. Every route also takes that link. - A message's id is
<chat id>_<Instagram's message id>, for example340282366841710301244276026398105347911_cAAAAB3xYz9wQkLmNo. Itsprovider_idis Instagram's message id alone. Because the id carries its chat,GET /messages/{message_id}needs nothing else. - An attachment's id is
<message provider_id>_<position>, from 0.
Which Calls Open A Conversation#
Instagram normally shows the other person "Seen" once a conversation is opened,
exactly as when the owner opens it. Lempile reads a conversation from the
inbox page's own load where it can, and opens it only when the inbox doesn't
hold what the call needs. An answer that opened a conversation with messages the
account hadn't seen says marks_seen: true.
| Never opens one | Opens one only when the inbox can't answer | Always opens it |
|---|---|---|
GET /chats |
One chat, its messages, its attendees, its sync; GET /messages and GET /messages/{message_id}; GET /chat_attendees and an attendee, their picture, chats and messages |
Every write in a chat |
List Chats#
curl -sS "https://api.lempile.com/api/v1/chats?account_id=$ACCOUNT_ID&limit=20" \
-H "X-API-KEY: $LEMPILE_API_KEY"{
"object": "ChatList",
"items": [
{
"object": "Chat",
"id": "340282366841710301244276026398105347911",
"account_id": "00000000-0000-4000-8000-0000000000c1",
"account_type": "INSTAGRAM",
"provider_id": "340282366841710301244276026398105347911",
"attendee_provider_id": "48210937561",
"name": null,
"type": 0,
"timestamp": "2026-11-25T17:41:07.000Z",
"unread_count": 1,
"archived": 0,
"muted_until": null,
"read_only": 0,
"folder": ["INBOX_INSTAGRAM_GENERAL"],
"pinned": 0
}
],
"cursor": "<cursor>"
}| Parameter | |
|---|---|
account_id |
Required. |
limit |
1 to 250 (default 20). |
cursor |
The previous page's cursor. null when there's no more. |
unread, before, after |
Not yet: 501. |
- Newest activity first, as Instagram lists them.
folderis["INBOX_INSTAGRAM_GENERAL"]for the inbox,["PENDING"]for a message request the account received.typeis0for one person,1for a group.attendee_provider_idis the other person in a one-to-one chat.account_idis the account's Lempile id, whichever form you sent.
One Chat#
curl -sS "https://api.lempile.com/api/v1/chats/$CHAT_ID?account_id=$ACCOUNT_ID" \
-H "X-API-KEY: $LEMPILE_API_KEY"The Chat, with its latest message as lastMessage (or null).
Messages#
curl -sS "https://api.lempile.com/api/v1/chats/$CHAT_ID/messages?account_id=$ACCOUNT_ID&limit=20" \
-H "X-API-KEY: $LEMPILE_API_KEY"{
"object": "MessageList",
"items": [
{
"object": "Message",
"id": "340282366841710301244276026398105347911_cAAAAB3xYz9wQkLmNo",
"message_id": "340282366841710301244276026398105347911_cAAAAB3xYz9wQkLmNo",
"provider_id": "cAAAAB3xYz9wQkLmNo",
"account_id": "00000000-0000-4000-8000-0000000000c1",
"chat_id": "340282366841710301244276026398105347911",
"chat_provider_id": "340282366841710301244276026398105347911",
"sender_id": "48210937561",
"sender_attendee_id": "48210937561",
"text": "See you at 10?",
"attachments": [],
"timestamp": "2026-11-25T17:41:07.000Z",
"is_sender": 0,
"reactions": [],
"seen": 1,
"seen_by": {},
"hidden": 0,
"deleted": 0,
"edited": 0,
"is_event": 0,
"delivered": 1,
"behavior": null,
"original": "",
"message_type": null
}
],
"cursor": "<cursor>"
}- Newest first.
limit1 to 250 (default 20);cursorfor the next page.before,afterandsender_id: not yet,501. is_senderis1for the account's own messages.message_typeisSTORY_MENTIONwhen the person mentioned the account in their story,STORY_REPLYwhen they answered one of its stories, andnullfor a plain message.reactions:{ value, sender_id, is_sender }, one per person.attachments: pictures (img), videos (video), voice notes (audio,voice_note: true), a shared post, reel or story (media_share, with itspostorstory), and a shared profile (profile). Each has aurl, Instagram's own link, which expires;GET /messages/{message_id}/attachments/{attachment_id}reads the file itself.
GET /messages/{message_id}?account_id= answers one Message. It's looked for
among its chat's newest 300 messages; an older one answers 404.
GET /messages?account_id=&limit= answers the messages of the newest chats,
newest first. It opens those chats.
Send A Message#
curl -sS -X POST "https://api.lempile.com/api/v1/chats/$CHAT_ID/messages" \
-H "X-API-KEY: $LEMPILE_API_KEY" \
-H "Idempotency-Key: answer-jane-1" \
-H "Content-Type: application/json" \
-d '{ "account_id": "'"$ACCOUNT_ID"'", "text": "Thanks, talk tomorrow." }'201:
{ "object": "MessageSent", "message_id": "340282366841710301244276026398105347911_cAAAAB3xYz9wQkLmNo" }| Field | |
|---|---|
account_id |
Required. |
text |
Up to 1,000 characters (Instagram's own limit). Needed unless there are files. |
attachments |
Files, in a multipart/form-data body: JPEG or PNG pictures (8 MB each), MP4 or MOV videos (25 MB), and voice notes as M4A, AAC or MP3 (10 MB). 10 files and 25 MB at most in all. Any other type: 415. A voice note may also come as voice_message. |
quote_id |
A message id of this chat: answers that message, as Instagram's Reply does. |
dry_run |
true: everything up to the message box, nothing typed or sent. |
LinkedIn's and WhatsApp's fields (mentions, thread_id, typing_duration,
video_message) answer 400: nothing is sent.
Idempotency-Keyis required (a dry run needs none).- Lempile reads the message back from the chat before it answers, so
message_idis the message as Instagram has it. - 20 seconds between messages in chats, 80 a day per account.
Start A Chat#
curl -sS -X POST "https://api.lempile.com/api/v1/chats" \
-H "X-API-KEY: $LEMPILE_API_KEY" \
-H "Idempotency-Key: hello-sam-1" \
-H "Content-Type: application/json" \
-d '{ "account_id": "'"$ACCOUNT_ID"'", "attendees_ids": ["sam.example"], "text": "Hi Sam, thanks for the follow." }'201:
{
"object": "ChatStarted",
"chat_id": "340282366841710301244276026398105347911",
"message_id": "340282366841710301244276026398105347911_cAAAAB3xYz9wQkLmNo"
}attendees_idsnames one person: theirprovider_messaging_id(as Unipile asks), theirprovider_id, username,@usernameor profile link. Group chats aren't supported yet: two or more answer501.- When a chat with that person already exists, the message goes there.
- Someone who doesn't follow the account gets a message request. Until they
accept, Instagram allows one message, text only: a second answers
422 errors/cant_send_message. - 3 minutes between new chats, 20 a day per account.
- The same fields as a message in a chat:
text,attachments,dry_run.quote_idand LinkedIn's fields (linkedin,subject,video_message) answer400.
React To A Message#
curl -sS -X POST "https://api.lempile.com/api/v1/messages/$MESSAGE_ID/reaction" \
-H "X-API-KEY: $LEMPILE_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "account_id": "'"$ACCOUNT_ID"'", "reaction": "❤️" }'{ "object": "MessageReactionAdded", "success": true }Instagram keeps one reaction per person on a message: a new one replaces the
account's last. DELETE /messages/{message_id}/reaction (same body) takes it
off and answers MessageReactionRemoved.
Attendees#
GET /chats/{chat_id}/attendees?account_id= answers the people in a chat;
GET /chat_attendees?account_id= everyone the account has a chat with
(limit, cursor).
{
"object": "ChatAttendeeList",
"items": [
{
"object": "ChatAttendee",
"id": "48210937561",
"account_id": "00000000-0000-4000-8000-0000000000c1",
"provider_id": "48210937561",
"name": "Sam Example",
"is_self": 0,
"picture_url": "https://…",
"profile_url": "https://www.instagram.com/sam.example/",
"specifics": {
"provider": "INSTAGRAM",
"public_identifier": "sam.example",
"relationship_status": {
"following": true,
"followed_by": true,
"has_received_invitation": false,
"has_sent_invitation": false
}
}
}
]
}An attendee's id is the person's provider_id.
| Route | Answers |
|---|---|
GET /chat_attendees/{attendee_id} |
One ChatAttendee. |
GET /chat_attendees/{attendee_id}/picture |
Their profile picture, as an image. |
GET /chat_attendees/{attendee_id}/chats |
A ChatList: the account's one-to-one chat with them. |
GET /chat_attendees/{attendee_id}/messages |
A MessageList: the messages of that chat. |
Read A Chat Again#
GET /chats/{chat_id}/sync?account_id= reads the chat from Instagram now:
{ "object": "ChatHistorySync", "chat_id": "340282366841710301244276026398105347911", "status": "SYNC_DONE" }A chat Instagram no longer has answers status: "CHAT_DELETED", as on Unipile.
Not On Instagram's Web#
Deleting, editing or forwarding a message, and deleting, muting, archiving or
marking a chat read (PATCH /chats/{chat_id}) answer 501, as on Unipile.
Was this page helpful?