> For the complete documentation index, see [llms.txt](https://user.netmera.com/netmera-developer-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://user.netmera.com/netmera-developer-guide/platforms/react-native/push-inbox.md). Agents can also search and read this documentation through its [MCP server](https://user.netmera.com/netmera-developer-guide/~gitbook/mcp).

# Push Inbox

### Push Inbox Overview

`NetmeraInbox` allows you to access and manage previously sent push notifications in an inbox-style interface. You cannot instantiate `NetmeraInbox` directly; instead, you must obtain an instance through the SDK and use it to interact with push notifications.

### Filtering Notifications

Create an instance to specify which push notifications to fetch. You can filter by:

* **Status**: Read, Unread, or Deleted.
* **Categories**: Filter by specific categories.
* **Expired Notifications**: Include or exclude expired notifications.
* **Page Size**: Number of notifications to fetch per request.

Here is a sample code to determine filtering options:

```typescript
import { Netmera, NetmeraInboxFilter, NMInboxStatus } from 'react-native-netmera'; 

const netmeraInboxFilter = new NetmeraInboxFilter();

// Filter to show Read or Unread notifications
netmeraInboxFilter.status = NMInboxStatus.STATUS_READ_OR_UNREAD;
netmeraInboxFilter.pageSize = 10;
netmeraInboxFilter.categories = ["category_1", "category_2"];
netmeraInboxFilter.includeExpiredObjects = true;
```

### Fetching the First Page

Use `fetchInbox` to retrieve notifications that match the filter:

```typescript
fetchInbox = async() => {
   try{
     const netmeraInboxFilter = new NetmeraInboxFilter()
     netmeraInboxFilter.status = NMInboxStatus.STATUS_READ_OR_UNREAD
     netmeraInboxFilter.pageSize = 10
     netmeraInboxFilter.categories = ["category_1", "category_2"]
     netmeraInboxFilter.includeExpiredObjects = true
     const inbox = await Netmera.fetchInbox(netmeraInboxFilter)
     console.log("inbox", inbox)
   }catch(e){
     console.log("error", e)
   }
 }
```

### Fetching Next Pages

Once the first page is retrieved, use `fetchNextPage` to get additional pages:

```typescript
fetchNextPage = async() => {
   try{
     const inbox = await Netmera.fetchNextPage()
     console.log("inbox", inbox)
   }catch(e){
     console.log("error", e)
   }
 }
```

### Updating Push Notification Status

A notification can have one of three statuses:

* Unread (`STATUS_UNREAD`)
* Read (`STATUS_READ`)
* Deleted (`STATUS_DELETED`)

`STATUS_READ_OR_UNREAD` and `STATUS_ALL` are filter values for fetching notifications with more than one status. They cannot be set as a notification's status.

Use `inboxUpdateStatusForPushObjects` to change the status of specific notifications. Pass the push objects returned by `fetchInbox` or `fetchNextPage`:

```typescript
const inbox = await Netmera.fetchInbox(netmeraInboxFilter);

// Mark the first two notifications as read
await Netmera.inboxUpdateStatusForPushObjects(
  inbox.slice(0, 2),
  NMInboxStatus.STATUS_READ
);
```

Each notification is matched by its `pushId` and `pushInstanceId`, so the right notifications are updated even if earlier updates changed the inbox list.

{% hint style="info" %}
**Note:** If any of the given notifications cannot be found in the current inbox, the promise is rejected with error code `2021` and no notification is updated. A notification leaves the inbox when it is fetched again with a filter that excludes it, or when its new status is outside the fetched filter. For example, after a notification is marked read in an inbox fetched with `STATUS_UNREAD`, updating it again (such as an undo) is rejected. To update the same notifications more than once, fetch the inbox with a filter that includes every target status, such as `STATUS_ALL`.
{% endhint %}

{% hint style="info" %}
**Note:** `inboxUpdateStatusForPushObjects` requires Netmera React Native SDK 2.4.0 or later. The index-based `inboxUpdateStatus(fromIndex, toIndex, status)` method is deprecated: once an update removes a notification from the inbox list, the indexes shift and the wrong notification may be updated.
{% endhint %}

### Updating The Status of All Notifications

You can update the status of all pushes inside inbox using `updateAll` method.

```javascript
await Netmera.updateAll(NMInboxStatus.STATUS_READ)
```

```javascript
await Netmera.updateAll(NMInboxStatus.STATUS_DELETED)
```

### Counting Notifications by Status

Retrieve the count of notifications by status:

```javascript
//get count of unread push objects
const count = await Netmera.countForStatus(NMInboxStatus.STATUS_UNREAD)

//get count of read push objects
const count = await Netmera.countForStatus(NMInboxStatus.STATUS_READ)
```

### Inbox Examples <a href="#inbox-examples" id="inbox-examples"></a>

```javascript
  const [inbox, setInbox] = useState<NetmeraPushObject[]>([]);
  const [inboxState, setInboxState] = useState(NMInboxStatus.STATUS_ALL);
  const [statusCount, setStatusCount] = useState('0');
  const [categoryList, setCategoryList] = useState('');

  const states = ['ALL', 'DELETED', 'READ_OR_UNREAD', 'READ', 'UNREAD'];

  const fetchInbox = async () => {
    try {
      const netmeraInboxFilter = new NetmeraInboxFilter();
      netmeraInboxFilter.status = inboxState;
      netmeraInboxFilter.pageSize = 2; // Fetch two push object

      if (categoryList.trim() !== '') {
        netmeraInboxFilter.categories = categoryList.split(' ');
      }

      const inbox = await Netmera.fetchInbox(netmeraInboxFilter);
      console.log('inbox', inbox);
      setInbox(inbox);
    } catch (e) {
      console.log('error', e);
    }
  };

  const fetchNextPage = async () => {
    try {
      const inbox = await Netmera.fetchNextPage();
      setInbox(inbox);
      console.log('inbox', inbox);
    } catch (e) {
      console.log('error', e);
    }
  };

  const updateAll = async () => {
    if (!inbox !== undefined) {
      if (inboxState === NMInboxStatus.STATUS_ALL) {
        Alert.alert('Error', 'Please select different status than all!!');
        console.log('Please select different status than all!!');
        return;
      }

      try {
        Netmera.updateAll(inboxState)
          .then(() => fetchInbox())
          .catch((error: any) => console.log('error: ' + error));
      } catch (error) {
        console.log('error: ' + error);
      }
    }
  };

  // Handles first push object
  const handlePushObject = async () => {
    if (inbox && inbox.length > 0 && inbox[0].pushId) {
      Netmera.handlePushObject(inbox[0].pushId);
    }
  };

  // Handles interactive action of first push object.
  const handleInteractiveAction = async () => {
    if (inbox !== undefined && inbox.length > 0) {
      inbox.map((pushObject: NetmeraPushObject) => {
        if (
          pushObject.interactiveActions &&
          pushObject.interactiveActions.length > 0
        ) {
          const action = pushObject.interactiveActions[0];
          if (!action?.id) return;
          Netmera.handleInteractiveAction(action.id);
        }
      });
    }
  };

  // Returns push object count by selected status.
  const countForStatus = async () => {
    try {
      const count = await Netmera.countForStatus(inboxState);
      setStatusCount(count.toString());
    } catch (error) {
      console.log('error: ' + error);
    }
  };

  // Update first two push object status to "UNREAD".
  const inboxUpdateStatus = async () => {
    if (inbox === undefined || inbox.length < 2) {
      Alert.alert('Error', 'Push objects count is less then 2!');
      return;
    }
    try {
      await Netmera.inboxUpdateStatusForPushObjects(
        inbox.slice(0, 2),
        NMInboxStatus.STATUS_UNREAD
      );
      console.log('2 push object status was changed successfully.');
    } catch (error) {
      console.log('error: ' + error);
    }
  };

  // Returns inbox count by selected status.
  const inboxCountForStatus = async () => {
    try {
      const filter = new NMInboxStatusCountFilter();
      filter.nmInboxStatus = inboxState;
      filter.includeExpired = true;

      if (categoryList.trim() !== '') {
        filter.categoryList = categoryList.split(' ');
      }

      const nmInboxStatusCount = await Netmera.getInboxCountForStatus(filter);

      let countStatusText =
        'ALL: ' +
        nmInboxStatusCount[NMInboxStatus.STATUS_ALL] +
        ', ' +
        'READ: ' +
        nmInboxStatusCount[NMInboxStatus.STATUS_READ] +
        ', ' +
        'UNREAD: ' +
        nmInboxStatusCount[NMInboxStatus.STATUS_UNREAD] +
        ', ' +
        'DELETED: ' +
        nmInboxStatusCount[NMInboxStatus.STATUS_DELETED];

      setStatusCount(countStatusText);
      console.log('nmInboxStatusCount: ', countStatusText);
    } catch (e) {
      console.log('error', e);
    }
  };

  const updateInboxState = (value: any) => {
    switch (value) {
      case 'ALL':
        setInboxState(NMInboxStatus.STATUS_ALL);
        break;

      case 'DELETED':
        setInboxState(NMInboxStatus.STATUS_DELETED);
        break;

      case 'READ_OR_UNREAD':
        setInboxState(NMInboxStatus.STATUS_READ_OR_UNREAD);
        break;

      case 'READ':
        setInboxState(NMInboxStatus.STATUS_READ);
        break;

      case 'UNREAD':
        setInboxState(NMInboxStatus.STATUS_UNREAD);
        break;
    }
  };
```

### Message Categories

{% hint style="info" %}
The per-channel message category preference APIs described in this section require **Netmera React Native SDK 2.2.1** or later. React Native SDK 2.2.1 bundles Netmera Android SDK **4.21.0** and Netmera Swift SDK **4.26.0**, which provide channel support on the native side.
{% endhint %}

Create message categories from **Settings > Messaging & Content > Message Categories** in the panel. Each category can be managed **per channel** (Mobile Push, SMS, Email, WhatsApp, In-App, Web) so you can track and update a user's opt-in status either for the category as a whole or for one specific channel.

Channels are represented by the `NMCategoryChannel` enum:

```typescript
enum NMCategoryChannel {
  MOBILE = 'MOBILE',
  SMS = 'SMS',
  EMAIL = 'EMAIL',
  WHATS_APP = 'WHATS_APP',
  IN_APP = 'IN_APP',
  WEB = 'WEB',
}
```

#### Getting a User's Category Preferences

Fetch the full list of category preferences (ID, name, and opt-in status):

```typescript
const categories = await Netmera.getUserCategoryPreferenceList();
```

To narrow the result down, pass an `NMCategoryPreferenceFilter` with a list of category IDs, channels, or both. `categoryIds` and `channels` are optional and independent; provide either, both, or neither.

```typescript
const filter = new NMCategoryPreferenceFilter();
filter.categoryIds = [42, 43];
filter.channels = [NMCategoryChannel.SMS, NMCategoryChannel.EMAIL];

const categories = await Netmera.getUserCategoryPreferenceList(filter);

categories.forEach((category) => {
  // Aggregate opt-in status, regardless of the channel filter
  console.log(category.categoryId, category.categoryName, category.optInStatus);

  // Per-channel breakdown
  category.channelPreferences?.forEach((channelPreference) => {
    console.log(channelPreference.channel, channelPreference.optInStatus);
  });
});
```

Calling `getUserCategoryPreferenceList()` without a filter returns every category with its aggregate status, the same as before channel support was added.

Each `NMCategoryPreference` includes:

* `categoryId` (`number`) — the category's identifier.
* `categoryName` (`string`) — the category's display name.
* `optInStatus` (`boolean`) — the overall status: `true` if the category is enabled on **any** channel. This is always returned, regardless of channel filters.
* `channelPreferences` (`NMCategoryChannelPreference[]`) — a per-channel breakdown, each with `channel` and its own `optInStatus`.

#### Updating Category Preferences

To turn a category on or off, pass an `NMCategoryPreferenceUpdate` with the category ID and the new `categoryEnabled` value:

```typescript
// Update the whole category (all channels)
await Netmera.setUserCategoryPreference(
  new NMCategoryPreferenceUpdate(42, true)
);
```

To update just one channel instead of the whole category, add a `channel`:

```typescript
// Update a single channel only
await Netmera.setUserCategoryPreference(
  new NMCategoryPreferenceUpdate(42, false, NMCategoryChannel.SMS)
);
```

{% hint style="info" %}
**Note:** The older `Netmera.setUserCategoryPreference(categoryId, categoryEnabled)` form still works but is deprecated. It behaves the same as passing an `NMCategoryPreferenceUpdate` without a `channel`. Only the `NMCategoryPreferenceUpdate` form accepts a `channel`.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://user.netmera.com/netmera-developer-guide/platforms/react-native/push-inbox.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
