Get group count no longer returns count

https://api-us.cometchat.io/v2.0/users/participant-local-7088/groups/cardgroup-local-2/messages?count=true used to return a count property in the data object, now it is missing. How do I get counts?

Yes, that is correct. In v2, we’ve moved to a cursor based approach. Cursoring separates results into pages and provides a means to move backwards and forwards through these pages. Cursoring has helped us reduce our API response-times drastically.

In most use cases, you should not have the need to retrieve the count. But let me know how you are planning to use this information and I can try and suggest a workaround.

We need to know the unread count for a group. So you’re saying the count=true and unread=true arguments no longer work? Because if I set both to true, I get this, which is not useful:

{ "data": [ { "entityId": "cardgroup-local-2", "entityType": "group", "updatedAt": 1575494828, "createdAt": 1575494828 } ], "meta": { "pagination": { "total": 0, "count": 1, "per_page": 100, "current_page": 1, "total_pages": 1 } } }

I mean, why send pagination when I just want a count?

Hi Eric,

The query param count=1 returns number of message.
The API response filters the empty and zero values to reduce the data transfer over network. As such the response share by you doesn’t contain count key for the entities with zero unread messages. For non-zero unread message count the response looks like:

{
    "data": [{
        "entityId": "supergroup",
        "entityType": "group",
        "count": 10,
        "updatedAt": 1575614792,
        "createdAt": 1574669032
    }],
    "meta": {
        "pagination": {
            "total": 1,
            "count": 1,
            "per_page": 100,
            "current_page": 1,
            "total_pages": 1
        }
    }
}

The query param unread=1 processes the request only for the unread messages.
If there isn’t any conversation with unread message for the user the response looks like:

{
    "data": [],
    "meta": {
        "pagination": {
            "total": 0,
            "count": 0,
            "per_page": 100,
            "current_page": 1,
            "total_pages": 1
        }
    }
}

The api endpoint for an API to fetch group chat messages for a user (https://api-us.cometchat.io/v2.0/users/{uid}/groups/{guid}/messages) is specialization of an api to fetch messages for a user(https://api-us.cometchat.io/v2.0/users/{uid}/messages). As such the pagination meta is present in the response providing additional information about the data. Thank you for your inputs regarding this. We’ll think over it.

Please note that the total and total_pages keys are deprecated and are present to offer backward compatibility.

2 Likes

A post was split to a new topic: Delivery & Read Receipts

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.