# Pagination of Unread messages of a user group channels

**URL:** <https://community.sendbird.com/t/pagination-of-unread-messages-of-a-user-group-channels/4477>\
**Category:** JavaScript\
**Tags:** group-channel\
**Created:** [April 19, 2022, 9:38am UTC](https://community.sendbird.com/t/pagination-of-unread-messages-of-a-user-group-channels/4477 "2022-04-19T09:38:35Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![BCH](https://avatars.discourse-cdn.com/v4/letter/b/f475e1/32.png) [@BCH](https://community.sendbird.com/u/BCH)\
**Post date:** [April 19, 2022, 9:38am UTC](https://community.sendbird.com/t/pagination-of-unread-messages-of-a-user-group-channels/4477/1 "2022-04-19T09:38:35Z")

</div>

How to fetch a unread messages of the group channels of a user with limit and offset?

Can someone post a api query how it can be done?

Thanks in Advance.

---

<div class="post-metadata">

**Author:** ![taha.saghir](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/taha.saghir/32/2094_2.png) [@taha.saghir](https://community.sendbird.com/u/taha.saghir)\
**Post date:** [April 19, 2022, 9:21pm UTC](https://community.sendbird.com/t/pagination-of-unread-messages-of-a-user-group-channels/4477/3 "2022-04-19T21:21:15Z")

</div>

Hi @BCH - thank you for reaching out to Sendbird!

Are you looking to retrieve the messages that the specific user has not read or the messages sent by the user that are unread?

Seems like you are looking for [previous message query](https://sendbird.com/docs/chat/v3/javascript/guides/group-channel#2-load-previous-messages). It doesn’t have a filter to fetch the unread messages only.

Understanding your use case will help suggest other solutions. Are you open to using Platform API or JS SDK only?

---

<div class="post-metadata">

**Author:** ![BCH](https://avatars.discourse-cdn.com/v4/letter/b/f475e1/32.png) [@BCH](https://community.sendbird.com/u/BCH)\
**Post date:** [April 20, 2022, 4:53am UTC](https://community.sendbird.com/t/pagination-of-unread-messages-of-a-user-group-channels/4477/4 "2022-04-20T04:53:38Z")

</div>

Hi @taha.saghir ,

Thanks for your response.

Our use case is One user is part of multiple group channels and has unread messages from other users in the group channels.

Lets a User A is part of 100 group channels and has messages sent by other users in all hundred group channels.

I want to query using send bird platform api to pull the unread message count from the group channels.

Want pull first 20 group channels which has highest unread messages and pull the next 20 when the user moves from the page to page.

We are using this GET https://api-{application\_id}.sendbird.com/v3/users/{user\_id}/my\_group\_channels?limit=20&query\_type=OR&unread\_filter=unread\_message"

how to fetch the next 20?

Let me know if any other info is needed

---

<div class="post-metadata">

**Author:** ![taha.saghir](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/taha.saghir/32/2094_2.png) [@taha.saghir](https://community.sendbird.com/u/taha.saghir)\
**Post date:** [April 20, 2022, 4:12pm UTC](https://community.sendbird.com/t/pagination-of-unread-messages-of-a-user-group-channels/4477/5 "2022-04-20T16:12:51Z")

</div>

Hi @BCH,

Please refer to the `next` property in the service [response](https://sendbird.com/docs/chat/v3/platform-api/user/managing-group-channels/list-group-channels#2-response).

> The value that can be used in the `token` parameter to retrieve the next page in the result set.

---

<div class="post-metadata">

**Author:** ![BCH](https://avatars.discourse-cdn.com/v4/letter/b/f475e1/32.png) [@BCH](https://community.sendbird.com/u/BCH)\
**Post date:** [April 21, 2022, 7:45am UTC](https://community.sendbird.com/t/pagination-of-unread-messages-of-a-user-group-channels/4477/6 "2022-04-21T07:45:05Z")

</div>

Thanks @taha.saghir … I will verify it

---

<div class="post-metadata">

**Author:** ![BCH](https://avatars.discourse-cdn.com/v4/letter/b/f475e1/32.png) [@BCH](https://community.sendbird.com/u/BCH)\
**Post date:** [April 21, 2022, 9:05am UTC](https://community.sendbird.com/t/pagination-of-unread-messages-of-a-user-group-channels/4477/7 "2022-04-21T09:05:19Z")

</div>

Hi @taha.saghir ,

I have checked the api and working fine.

https://api-{0}.sendbird.com/v3/users/{userid}/my\_group\_channels?limit=10&token=blahblah&query\_type=OR&unread\_filter=unread\_message

is working to move forward.

Lets say I fetch 10 per page, after fetching next 10 - how should I go back to fetch first 10 again?

---

<div class="post-metadata">

**Author:** ![taha.saghir](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/taha.saghir/32/2094_2.png) [@taha.saghir](https://community.sendbird.com/u/taha.saghir)\
**Post date:** [April 21, 2022, 5:21pm UTC](https://community.sendbird.com/t/pagination-of-unread-messages-of-a-user-group-channels/4477/8 "2022-04-21T17:21:18Z")

</div>

You can do that by removing the token param or leaving it blank.

---

<div class="post-metadata">

**Author:** ![BCH](https://avatars.discourse-cdn.com/v4/letter/b/f475e1/32.png) [@BCH](https://community.sendbird.com/u/BCH)\
**Post date:** [April 22, 2022, 5:01pm UTC](https://community.sendbird.com/t/pagination-of-unread-messages-of-a-user-group-channels/4477/9 "2022-04-22T17:01:08Z")

</div>

Thanks @taha.saghir … What I meant was is there anything like **before** parameter like **next**.

I think we need to store the **next** value for every fetch query, before and after need to be fetched based on that.

One more question - Is there any api that I can make the Mark all messages read in the channel for a user?

---

<div class="post-metadata">

**Author:** ![taha.saghir](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/taha.saghir/32/2094_2.png) [@taha.saghir](https://community.sendbird.com/u/taha.saghir)\
**Post date:** [April 22, 2022, 7:16pm UTC](https://community.sendbird.com/t/pagination-of-unread-messages-of-a-user-group-channels/4477/10 "2022-04-22T19:16:00Z")

</div>

Hi @BCH - there is no API level iterator to go back, you will have to manage it on your end.

Here is the API to [mark all messages read](https://sendbird.com/docs/chat/v3/platform-api/user/marking-messages-as-read/mark-all-messages-as-read-user#1-mark-all-messages-as-read).

---

<div class="post-metadata">

**Author:** ![BCH](https://avatars.discourse-cdn.com/v4/letter/b/f475e1/32.png) [@BCH](https://community.sendbird.com/u/BCH)\
**Post date:** [April 26, 2022, 10:28am UTC](https://community.sendbird.com/t/pagination-of-unread-messages-of-a-user-group-channels/4477/11 "2022-04-26T10:28:13Z")

</div>

Thank you for your responses @taha.saghir . This info is really helpful.

---

<div class="post-metadata">

**Author:** ![BCH](https://avatars.discourse-cdn.com/v4/letter/b/f475e1/32.png) [@BCH](https://community.sendbird.com/u/BCH)\
**Post date:** [April 26, 2022, 3:08pm UTC](https://community.sendbird.com/t/pagination-of-unread-messages-of-a-user-group-channels/4477/12 "2022-04-26T15:08:17Z")

</div>

Hi @taha.saghir ,

Hopefully this is my last doubt in this thread. 🙂

How to sort by the unread messages descending order in the my\_group\_channels api ?

---

<div class="post-metadata">

**Author:** ![taha.saghir](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/taha.saghir/32/2094_2.png) [@taha.saghir](https://community.sendbird.com/u/taha.saghir)\
**Post date:** [April 26, 2022, 3:59pm UTC](https://community.sendbird.com/t/pagination-of-unread-messages-of-a-user-group-channels/4477/13 "2022-04-26T15:59:01Z")

</div>

Anytime @BCH, here to help!

`my_group_channels` API is to list the channels. To get the message, use the [list messages](https://sendbird.com/docs/chat/v3/platform-api/message/messaging-basics/list-messages) API. Please refer to the `reverse` parameter.

---

<div class="post-metadata">

**Author:** ![BCH](https://avatars.discourse-cdn.com/v4/letter/b/f475e1/32.png) [@BCH](https://community.sendbird.com/u/BCH)\
**Post date:** [May 4, 2022, 4:46pm UTC](https://community.sendbird.com/t/pagination-of-unread-messages-of-a-user-group-channels/4477/14 "2022-05-04T16:46:50Z")

</div>

Hi @taha.saghir ,

Thanks for your response.

To get the message, use the [list messages](https://sendbird.com/docs/chat/v3/platform-api/message/messaging-basics/list-messages) API. Please refer to the `reverse` parameter.

1. Here the url is expecting channelurl but i want the unread messages of all the channels that user is part of and in unread count descending order.

2. Here is the API to [mark all messages read](https://sendbird.com/docs/chat/v3/platform-api/user/marking-messages-as-read/mark-all-messages-as-read-user#1-mark-all-messages-as-read). How many channel\_urls i can pass in the request body?

---

<div class="post-metadata">

**Author:** ![taha.saghir](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/taha.saghir/32/2094_2.png) [@taha.saghir](https://community.sendbird.com/u/taha.saghir)\
**Post date:** [May 9, 2022, 1:46pm UTC](https://community.sendbird.com/t/pagination-of-unread-messages-of-a-user-group-channels/4477/15 "2022-05-09T13:46:55Z")

</div>

Hi @BCH – sorry for the delay in getting back to you.

Here are the responses:

1. There is no such API. It will require customization on your end to get the consolidated list of unread messages that you need. Please review the [unread items APIs](https://sendbird.com/docs/chat/v3/platform-api/user/getting-statistics-on-unread-items/view-number-of-unread-messages), if these could be of any help to you.
2. Technically, there is no limit to the number of URLs you can pass. You may get hit by the http request body character limit – that I’m not sure if there is any.

---

<div class="post-metadata">

**Author:** ![BCH](https://avatars.discourse-cdn.com/v4/letter/b/f475e1/32.png) [@BCH](https://community.sendbird.com/u/BCH)\
**Post date:** [May 9, 2022, 5:44pm UTC](https://community.sendbird.com/t/pagination-of-unread-messages-of-a-user-group-channels/4477/16 "2022-05-09T17:44:46Z")

</div>

Thank you for your response @taha.saghir
