no-translate

Get all chats

Fetch a list of all chats or a bunch of chats
Napisany przez Konstantine
Zaktualizowano 8 miesięcy temu

You can get all of your chats or a bunch of chats with this method. If you want to get just one chat by its id, use Get a single chat method instead. To find chats by the value of their attributes, use Search for chats method.

➡️ Request

URL https://api.helpcrunch.com/v1/chats?sort=chats.closedAt&order=asc
Method GET
Headers Authorization: Bearer <your_api_key>

Sorting options

To sort chats in descending order, use order=desc parameter in the query string. For ascending order use order=asc

Sorting option Description
chats.createdAt by date of chat creation
chats.lastCustomerMessageAt by date of the last message from customer
chats.lastMessageAt by date of the last message from agent or customer
chats.closedAt by date chats were closed

✅ Successful Response

If your request has succeeded, you'll get a 200 OK success status code together with the following response body.

{
  "data": [
    {
      "id": 542335,
      "closedBy": "string",
      "lastCustomerMessageAt": "1603885746",
      "status": "new",
      "closedAt": "1603885746",
      "rating": "perfect",
      "createdAt": "1603885746",
      "lastMessageAt": "1603885746",
      "createdWith": "string",
      "snoozedUntil": "1603885746",
      "lastMessageText": "string",
      "lastMessageId": 542335,
      "applicationId": 542335,
      "lastCommunicatedAgentId": 542335,
      "agents": [
        {
          "id": 542335,
          "name": "string",
          "email": "string",
          "role": "string"
        }
      ],
      "customer": {
        "id": 542335,
        "name": "string",
        "email": "string",
        "userId": "string"
      },
      "assignee": {
        "id": 542335,
        "name": "string",
        "email": "string",
        "role": "string"
      },
      "department": {
        "id": 542335,
        "name": "string"
      }
    }
  ],
  "meta": {
    "total": 435
  }
}

You can get details on every Chat Object field in the Chat model article.

How to get all chats

By default, this method returns only the first 100 chats. To get a different set of chats, you should use the offset and limit parameters in the query string of the GET request.

Default limit is 100 and it can not be bigger than that. Default offset is 0

To page through all the available chats, first, use the meta section of the JSON response to get the total number of chats.

You can request .../chats/total to get just the total number of chats

Then send subsequent requests with increasing offsets and a fixed limit until you get all the data.  

https://api.helpcrunch.com/chats?offset=100&limit=100
https://api.helpcrunch.com/chats?offset=200&limit=100
https://api.helpcrunch.com/chats?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_request",
      "message": "Invalid request"
    },
    {
      "code": "customer",
      "message": "This value should be of type numeric."
    },
    {
      "code": "filter[0].field",
      "message": "This value should not be blank."
    }
  ]
}

401 Unauthorized

{
  "errors": [
    {
      "code": "invalid_request",
      "message": "Invalid request"
    },
    {
      "code": "unauthorized",
      "message": "Unauthorized"
    }
  ]
}

429 Too Many Requests

{
  "errors": [
    {
      "code": "invalid_request",
      "message": "Invalid request"
    },
    {
      "code": "too_many_requests",
      "message": "Too many requests"
    }
  ]
}

If you have any questions regarding the REST API, feel free to chat us any time.

👩‍💻 Happy Coding! 👨‍💻

Czy odpowiedzieliśmy na Twoje pytanie?