---
source_url: https://www.pubnub.com/docs/sdks/mbed/api-reference/storage-and-playback
title: Message Persistence API for Mbed SDK
updated_at: 2026-06-17T11:39:59.300Z
sdk_name: PubNub Mbed SDK
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Message Persistence API for Mbed SDK

PubNub Mbed SDK

Message Persistence gives you real-time access to the history of messages published to PubNub. Each message is timestamped to the nearest 10 nanoseconds and stored across multiple availability zones in several geographic locations. You can encrypt stored messages with AES-256 so they are not readable on PubNub’s network. For details, see [Message Persistence](https://www.pubnub.com/docs/general/storage).

You control how long messages are stored through your account’s retention policy. Options include: 1 day, 7 days, 30 days, 3 months, 6 months, 1 year, or Unlimited.

You can retrieve the following:

* Messages
* Message reactions
* Files (using the File Sharing API)

## History

This function fetches historical messages of a channel. Message Persistence provides real-time access to persisted messages. Stored messages are replicated across multiple availability zones in several geographic data center locations. Stored messages can be encrypted with AES-256 so they are not readable while stored on PubNub's network.

* Limit the number of messages to a specific quantity using the `4th argument` parameter.

### Method(s)

Use the following method(s) in the mbed SDK:

```c
enum pubnub_res pubnub_history (pubnub_t *p, const char *channel, const char *channel_group, unsigned count)
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| p | pubnub_t* | Yes |  | Pointer to PubNub client context. Can't be NULL. |
| channel | const | Yes |  | The `string` with the `channel` name to fetch the `history` |
| count | unsigned | Yes |  | Maximum number of messages to get. If there are less than this available on the `channel`, you'll get less, but you can't get more. |
| include_token | bool | Yes |  | If `true`, include the [timetoken](https://www.pubnub.com/docs/sdks/mbed/api-reference/misc#time) for every `message`. default: `false` |

### Sample code

Retrieve the last 100 messages on a channel:

```c
// Sync
enum pubnub_res res;

pubnub_history(
    pn,
    "history_channel",
    10,
    false
);
res = pubnub_await(pn);

if (PNR_OK == res) {
    puts("Got history! Messages:");
    for (;;) {
        const char *msg = pubnub_get(pn);
        if (NULL == msg) {
            break;
        }
        puts(msg);
    }
} else {
    printf("Getting history failed with code: %d\n", res);
}

### Rest response from server

An array is returned on success.
The `pubnub_history()` function returns a list of up to 100 messages, the timetoken of the first (oldest) message and the timetoken of the last (newest) message in the resulting set of messages. The output below demonstrates the format for a `pubnub_history()` response:

```javascript showLineNumbers
[
    ["message1", "message2", "message3",... ],
    "Start Time Token",
    "End Time Token"
]
```

## Terms in this document

* **Message** - A unit of data transmitted between clients or between a client and a server in PubNub, containing information such as text, binary data, or structured data formats like JSON. Messages are sent over channels and can be tracked for delivery and read status.
* **PubNub** - PubNub is a real-time messaging platform that provides APIs and SDKs for building scalable applications. It handles the complex infrastructure of real-time communication, including: Message delivery and persistence, Presence detection, Access control, Push notifications, File sharing, Serverless processing with Functions and Events & Actions, Analytics and monitoring with BizOps Workspace, AI-powered insights with Illuminate.