---
source_url: https://www.pubnub.com/docs/sdks/javascript/api-reference/message-persistence-legacy
title: "Message Persistence API: deprecated history() method and actions data property for JavaScript SDK"
updated_at: 2026-11-09T13:29:01.000Z
sdk_name: PubNub JavaScript SDK
sdk_version: 13.1.3
description: Deprecated. Reference for the pubnub.history() method and the data property of actions in fetchMessages() responses in the PubNub JavaScript SDK. Message Persistence itself is current. New apps use fetchMessages() and read actions.
lifecycle: deprecated-method
feature_status: current
feature: Message Persistence
replaced_by: https://www.pubnub.com/docs/sdks/javascript/api-reference/message-persistence.md
---

# Message Persistence API: deprecated history() method and actions data property for JavaScript SDK

PubNub JavaScript SDK, use the latest version: 13.1.3

Install:

```bash
npm install pubnub@13.1.3
```

> For AI agents: documentation index at https://www.pubnub.com/llms-full.txt

> **Deprecated.** The Message Persistence feature is current and fully supported. Only the method documented on this page is deprecated. Do not use it in new code. Explain it only to developers who already call it.
>
> Page notice: Message Persistence is a current API. The history() method and the data property of actions are deprecated. New apps should use fetchMessages() and read actions.
>
> Current API: https://www.pubnub.com/docs/sdks/javascript/api-reference/message-persistence.md

This page documents the deprecated `pubnub.history()` method and the deprecated `data` property of `actions` in `fetchMessages()` responses in the PubNub JavaScript SDK. Message Persistence is a current API, and only these two are deprecated. They remain for apps that already use them. New apps call [`fetchMessages()`](https://www.pubnub.com/docs/sdks/javascript/api-reference/message-persistence.md#fetch-history) and read `actions`.

## History (deprecated)

:::warning Deprecated
`history()` is deprecated in the JavaScript SDK. Use [`fetchMessages()`](https://www.pubnub.com/docs/sdks/javascript/api-reference/message-persistence.md#fetch-history) instead.
:::

:::note Requires Message Persistence add-on
This method requires that the *Message Persistence* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). See [Enable the features your app calls](https://www.pubnub.com/docs/architecture/authentication/set-up-your-account.md#enable-the-features-your-app-calls).
:::

`history()` fetches the messages of one channel. You can control how it returns messages and in what order:

* By default, the search starts at the newest end of the timeline, which is `reverse` set to `false`.
* To search from the oldest end of the timeline, set `reverse` to `true`.
* To page through results, provide `start` or `end`.
* To retrieve a slice of the timeline, provide both `start` and `end`.
* To limit the number of messages, use `count`.

### Method(s)

```typescript
pubnub.history({
    channel: string,
    reverse?: boolean,
    count?: number,
    stringifiedTimeToken?: boolean,
    includeMeta?: boolean,
    start?: string,
    end?: string
}): Promise<GetHistoryResponse>;
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| channel | string | Yes | n/a | ID of the channel to return history messages from. |
| reverse | boolean | Optional | `false` | Whether to traverse the timeline from the oldest message to the newest. If you provide both `start` and `end`, `history()` ignores `reverse` and returns the messages starting with the newest one. |
| count | number | Optional | `100` | Number of messages to return. The maximum is `100`, and `history()` lowers a larger value to `100`. |
| stringifiedTimeToken | boolean | Optional | `false` | Whether to return timetokens as strings. |
| includeMeta | boolean | Optional | `false` | Whether to include the `meta` object, if the publisher set one at publish time, in each message of the response. |
| start | string | Optional | n/a | Timetoken that sets the newer boundary of the query (exclusive). Retrieval begins at this timetoken and moves backward in time. With `end`, `start` must be a higher timetoken than `end`. |
| end | string | Optional | n/a | Timetoken that sets the older boundary of the query (inclusive). Retrieval stops at this timetoken. With `start`, `end` must be a lower timetoken than `start`. |

`history()` always returns the messages sorted from the oldest to the newest, whatever `reverse` is. The `reverse` setting matters when more than `100` messages, or more than `count` if you set it, fall in the time interval. In that case, `reverse` decides which end of the interval the retrieval starts from.

### Sample code

Retrieve the last 100 messages on a channel:

```javascript
try {
    const result = await pubnub.history({
        channel: "history_channel",
        count: 100, // how many items to fetch
        stringifiedTimeToken: true, // false is the default
    });
} catch (status) {
    console.log(status);
}
```

### Returns

`history()` resolves with an object that has these properties. With a callback, `status.operation` is `PNHistoryOperation`.

| Property | Type | Description |
| --- | --- | --- |
| messages | array | The returned messages. Each item has `entry`, `timetoken`, and, when present, `meta` and `error`. |
| startTimeToken | string or number | Timetoken of the start of the returned timeline. |
| endTimeToken | string or number | Timetoken of the end of the returned timeline. |

In each item of `messages`, `entry` holds the decrypted message payload and `timetoken` holds the message timetoken. The `meta` property is present only when the publisher set metadata. The `error` property is present only when the SDK fails to decrypt the message.

```javascript
{
    endTimeToken: "14867650866860159",
    messages: [
        {
            timetoken: "14867650866860159",
            entry: "[User 636] hello World"
        },
        {...},
        {...},
        {...}
    ],
    startTimeToken: "14867650866860159"
}
```

### Other examples

#### Retrieve the three oldest messages

Set `reverse` to `true` to traverse the timeline from the oldest message first.

```javascript
try {
    const result = await pubnub.history({
        channel: "my_channel",
        reverse: true, // Setting to true will traverse the time line in reverse starting with the oldest message first.
        count: 3, // how many items to fetch
        stringifiedTimeToken: true, // false is the default
    });
} catch (status) {
    console.log(status);
}
```

#### Retrieve messages newer than a timetoken

Page from the oldest message to the newest, starting at a single point in time (exclusive).

```javascript
try {
    const result = await pubnub.history({
        channel: "my_channel",
        reverse: true, // Setting to true will traverse the time line in reverse starting with the oldest message first.
        stringifiedTimeToken: true, // false is the default
        start: "13406746780720711", // start timetoken to fetch
    });
} catch (status) {
    console.log(status);
}
```

#### Retrieve messages until a timetoken

Page from the newest message to the oldest, until a specific point in time (inclusive).

```javascript
try {
    const result = await pubnub.history({
        channel: "my_channel",
        stringifiedTimeToken: true, // false is the default
        end: "13406746780720711", // end timetoken to fetch
    });
} catch (status) {
    console.log(status);
}
```

#### Page through all messages

Call the function with no argument or with a valid timetoken.

```javascript
async function getAllMessages(initialTimetoken = '') {
  const allMessages = [];
  let latestCount = 100;
  let timetoken = initialTimetoken;

  while (latestCount === 100) {
    const { messages, startTimeToken, endTimeToken } = await pubnub.history(
      {
        channel: 'history_test',
        stringifiedTimeToken: true, // false is the default
        start: timetoken, // start timetoken to fetch
      }
    );

    latestCount = messages.length;
    timetoken = String(startTimeToken);

    if (messages && messages.length > 0) {
      allMessages.push(...messages);
    }
  }

  return allMessages;
}

// Usage examples:
// await getAllMessages();
// await getAllMessages("12345678901234");
```

#### Fetch messages with metadata

```javascript
try {
    const result = await pubnub.history({
        channel: "my_channel",
        stringifiedTimeToken: true,
        includeMeta: true,
    });
} catch (status) {
    console.log(status);
}
```

#### Call history with promises

```javascript
pubnub.history({
  channel: 'history_channel',
  reverse: true, // Setting to true will traverse the time line in reverse starting with the oldest message first.
  count: 100, // how many items to fetch
  stringifiedTimeToken: true, // false is the default
  start: '123123123133', // start timetoken to fetch
  end: '123123123123', // end timetoken to fetch
}).then((response) => {
  console.log(response);
}).catch((error) => {
  console.log(error);
});
```

## Deprecated data property of actions

:::warning Deprecated
The `data` property of `actions` is deprecated. Read `actions` instead.
:::

`fetchMessages()` returns message actions on each message in `actions`, grouped by action type and then by action value. The response has them only with `includeMessageActions` and when the message has actions. The deprecated `data` property holds the same value as `actions`.

| Property | Type | Description | Replacement |
| --- | --- | --- | --- |
| data | object | Holds the same value as `actions`. | `actions` |

See [Fetch history](https://www.pubnub.com/docs/sdks/javascript/api-reference/message-persistence.md#response) for the full response.

Last updated at: 2026-11-09T13:29:01.000Z
