New Feature Release: Message Counts API

2 min readMar 15, 2019

Users expect those little red circles with how many unread messages they have. However, it can be surprisingly hard to do. So we’re making it super easy for you to implement them.

We’re excited to announce the release of our new API – Message Counts – enabling the retrieval of message counts, on a per channel basis, and using a single API call, of messages published to multiple channels after a specified timestamp (time-token).

The new endpoint powers unread messages functionality without complexity or the use of 3rd party services. It’s optimized for mobile and other low latency use cases – providing a more efficient and bandwidth/battery saving way to retrieve message counts.

Technical Details

This new API allows for a simple query that determines the count of unread messages for a list of channels and related times. A list of the channels with the count of messages, given actual publishing occurring after the passed-in time token, is returned. You can take this result and easily apply it to the user interface, (e.g. the badge counts on a chat application), or in other systems/processes.

Full documentation for the REST API is available in the Message Counts API docs. At release, the following SDKs support the Message Counts API:

  • Objective-C
  • Swift
  • Java
  • JavaScript
  • Go
  • Unity
  • Python
  • PHP
  • C#

Why We Built It

We live and breathe real-time at PubNub, and that term ‘real-time’ often connotes now or instantaneous. However, applications and systems cannot always assume constant connectivity. So you need a way to ensure consumers (subscribers) of the data, whether people or devices, can “catch-up” with the real-time data stream, allowing them to see messages sent to various channels since the last time they, or it, checked or logged in.

Thus, we needed to provide developers the ability to add capabilities into their real-time applications that allow subscribers to understand which subscribed channels have published messages in them, within a certain time horizon. This allows for a streamlined user experience, eliminating the need for constant manual clicking to see if a channel has new data in it, since last login or app visit.

Use Cases

Beyond chat, there are many other use cases for the Message Counts API. Knowing how many messages have flowed through a channel since it was last accessed can power all sorts of logic. If a particular sensor, for instance, has tried to send a high volume of messages while the core server was disconnected, it should be prioritized for attention. Fundamentally, being able to tell the activity level on a channel quickly can often tell a better and more useful story than receiving a slew of messages to sort through.


More from PubNub

How to Create a Dating App: 7 Steps to Fit Any Design
Insights6 minMar 15, 2023

How to Create a Dating App: 7 Steps to Fit Any Design

There are common underlying technologies for a dating app, and in this post, we’ll talk about the major technologies and designs...

Michael Carroll

Michael Carroll

How to Create a Real-time Public Transportation Schedule App
Build6 minMar 14, 2023

How to Create a Real-time Public Transportation Schedule App

How to use geohashing, JavaScript, Google Maps API, and BART API to build a real-time public transit schedule app.

Michael Carroll

Michael Carroll

How to Create Real-Time Vehicle Location Tracking App
Build2 minMar 9, 2023

How to Create Real-Time Vehicle Location Tracking App

How to track and stream real-time vehicle location on a live-updating map using EON, JavaScript, and the Mapbox API.

Michael Carroll

Michael Carroll

Talk to an expert