You can get all the messages from any chat by its id. To find a specific chat by the value of its attributes, use Search for chats method.
➡️ Request
URL | https://api.helpcrunch.com/v1/chats/<chat_id>/messages |
Method | GET |
Headers | Authorization: Bearer <your_api_key> |
<chat_id> is the identifier for the chat as given by HelpCrunch. It is required for this method and looks like a combination of numbers, for example 1568834.
Read more about authorization header here.
✅ Successful Response
If your request has succeeded, you'll get a 200 OK success status code together with the following response body.
{
"data": [
{
"id": 9577571,
"agent": null,
"type": "message",
"text": "Can you can a can as a canner can can a can?",
"read": true,
"createdAt": "1594139170.913",
"updatedAt": "1594291329.303",
"edited": false,
"broadcastType": null,
"chat": 5215261,
"from": "customer"
},
{
"id": 9577570,
"agent": null,
"type": "message",
"text": "How much wood would a wodchuck chuck if a woodchuck could chuck wood?",
"read": true,
"createdAt": "1593888597.787",
"updatedAt": "1593888609.369",
"edited": false,
"broadcastType": null,
"chat": 5215261,
"from": "customer"
},
{
"id": 9577569,
"agent": null,
"type": "You know like this one",
"text": "swerwer",
"read": true,
"createdAt": "1593888351.465",
"updatedAt": "1593888360.057",
"edited": false,
"broadcastType": null,
"chat": 5215261,
"from": "customer"
},
{
"id": 9577568,
"agent": null,
"type": "Do you know some tongue twisters?",
"text": "sdfsdfsdf",
"read": true,
"createdAt": "1593887608.482",
"updatedAt": "1593887614.872",
"edited": false,
"broadcastType": null,
"chat": 5215261,
"from": "customer"
},
{
"id": 9577567,
"agent": {
"id": 4188,
"name": "Frodo"
},
"type": "message",
"text": "Hello, how can I help you?",
"read": true,
"createdAt": "1593887537.924",
"updatedAt": "1593887595.272",
"edited": false,
"broadcastType": null,
"chat": 5215261,
"from": "agent"
},
],
"total": 5
}
All messages are sorted by createdAt date in a descending order, meaning that the last message from the chat will be the first one in the response.
You can get details on every Message Object field in the Message model article.
How to get all messages
By default, this method returns the last 100 messages from the chat. To get a different set of messages, you should use the offset and limit parameters in the query string of the GET request.
To page through all the available messages, first, use the total attribute of the JSON response to get the overall number of messages.
Then send subsequent requests with increasing offsets and a fixed limit until you get all the data.
https://api.helpcrunch.com/chats/1568834/messages?offset=100&limit=100
https://api.helpcrunch.com/chats/1568834/messages?offset=200&limit=100
https://api.helpcrunch.com/chats/1568834/messages?offset=300&limit=100
...
The overall requests limit is 120 per minute
🛑 Error Responses
You may get one of the following error status codes and responses. More info on the errors is available here.
400 Bad Request
{
"errors": [
{
"code": "invalid_chat_value",
"message": "Invalid chat ID"
}
]
}
401 Unauthorized
{
"errors": [
{
"code": "invalid_token",
"message": "Invalid token"
}
]
}
404 Not Found
{
"errors": [
{
"code": "chat_not_found",
"message": "Chat is missing"
}
]
}
404 Not Found
{
"errors": [
{
"code": "messages_not_found",
"message": "Messages are missing"
}
]
}
429 Too Many Requests
{
"errors": [
{
"code": "too_many_requests",
"message": "You have exceeded your requests limit"
}
]
}
If you have any questions regarding the REST API, feel free to chat us any time.
👩💻 Happy Coding! 👨💻