Get how many notifications a subscriber hasn't read, for your own unread badge.
Premium has no inbox
On Premium, every inbox call answers 201 with an explanation, so the SDK shows an empty inbox and an unread count of 0. See what each plan includes.
Get the unread count
getUnreadIndieNotificationInboxCount resolves with how many of a subscriber's notifications are unread. Show a bubble over your inbox icon while it's above 0.
import React, { useState, useEffect } from 'react';
import { getUnreadIndieNotificationInboxCount } from 'native-notify';
export default function Header() {
const [unreadNotificationCount, setUnreadNotificationCount] = useState(0);
const fetchUnreadCount = async () => {
try {
const unreadCount = await getUnreadIndieNotificationInboxCount(
"unique-user-id",
yourAppId,
'yourAppToken'
);
console.log("unreadCount: ", unreadCount);
setUnreadNotificationCount(unreadCount);
} catch (error) {
console.error("Error fetching unread notification count: ", error);
}
};
useEffect(() => {
fetchUnreadCount();
}, []);
return (
...
)
}
| Argument | Required | Notes |
|---|---|---|
subId | yes | The subscriber's registered id. |
appId, appToken | no | Your app's id and token from your Native Notify dashboard. Default to NativeNotify.init(). |
Fetching the inbox marks every notification read and drops the count to 0, unless you use per-notification read state.
Call the endpoint directly
GET https://app.nativenotify.com/api/indie/notification/inbox/read/{subId}/{appId}/{appToken}
| Status | Meaning |
|---|---|
201 | { "unreadCount": 3 }. |
201 with text | Premium: nothing is counted, so the SDK returns 0. |
401 | The appId and appToken pair doesn't match an app. |
A failed request (a 401, a network error) rejects, so keep the try / catch.