Skip to main content

Get WhatsApp Group Messages Programmatically

Agent Skill

Automate this endpoint with an AI agent using the 2chat-whatsapp skill:

npx skills add 2ChatCo/agent-skills -s 2chat-whatsapp

This endpoint will let you get WhatsApp group messages that were sent or received on your 2Chat-connected WhatsApp number. Only those messages sent/received after you made the connection to 2Chat will be returned.

Getting all messages​

info

You will first need to get the UUID of the group you want to pull messages from. You can do that by using this endpoint.

Assuming WAG4ca128c6-7f86-428f-8e9f-5eb65e045189 is the UUID of the target group:

https://api.p.2chat.io/open/whatsapp/groups/messages/WAG4ca128c6-7f86-428f-8e9f-5eb65e045189.

This call will return the last or newest 50 messages you received on that group. If you would like to see older ones, you can start paginating the results:

  • Page 1, from 50 to 100: https://api.p.2chat.io/open/whatsapp/groups/messages/WAG4ca128c6-7f86-428f-8e9f-5eb65e045189?page_number=1.
  • Page 2, from 100 to 150: https://api.p.2chat.io/open/whatsapp/groups/messages/WAG4ca128c6-7f86-428f-8e9f-5eb65e045189?page_number=2.
  • Page n: ...

Invocation​

curl --location --request GET 'https://api.p.2chat.io/open/whatsapp/groups/messages/WAG4ca128c6-7f86-428f-8e9f-5eb65e045189?page_number=0' \
--header 'X-User-API-Key: your_api_key_here' \
--data-raw ''

Response​

{
"success": true,
"page_number": 0,
"messages": [
{
"id": "MSGa9b1ea05-ab5b-4082-b36d-6dd297d861cb",
"uuid": "MSGa9b1ea05-ab5b-4082-b36d-6dd297d861cb",
"session_key": "WW-WPN66037eca-9ad1-4c96-9eff-526a90a48c77-111111111111111111@g.us",
"message": {
"text": "This is the latest message that was sent to this group",
"media": {
"url": "https://2chat-user-data-dev.s3.amazonaws.com/...jpeg",
"type": "image",
"mime_type": "image/jpeg"
}
},
"created_at": "2025-01-03T14:19:28",
"_2chat_link": "https://app.2chat.io/live-chat/STEc5ca017c-6e16-4e1a-9960-c180b1f51682/WW-WPN66037eca-9ad1-4c96-9eff-526a90a48c77-111111111111111111@g.us",
"sent_by": "user",
"participant": {
"phone_number": "+17131112222",
"device": "ios",
"pushname": "Person who sent the message"
}
},
...
]
}