# Read Heart Rate via WebSocket

This method allows reading the heart rate of the user in real-time. The WebSocket connection can be interrupted at any point in time, make sure to have retry logic with backoff.

**Request**

<table><thead><tr><th width="197">name</th><th>value</th></tr></thead><tbody><tr><td>url</td><td><code>wss://dev.pulsoid.net/api/v1/data/real_time</code></td></tr><tr><td>scope</td><td><code>data:heart_rate:read</code></td></tr></tbody></table>

**Authentication**

Provide your OAuth2 Bearer token using one of the following methods:

| Method          | Example                                                               |
| --------------- | --------------------------------------------------------------------- |
| Query parameter | `wss://dev.pulsoid.net/api/v1/data/real_time?access_token=YOUR_TOKEN` |
| Header          | `Authorization: Bearer YOUR_TOKEN`                                    |

**Query Parameters explained:**

<table><thead><tr><th width="186">name</th><th width="103">type</th><th>description</th></tr></thead><tbody><tr><td>access_token</td><td>string</td><td>OAuth2 access token (alternative to Authorization header)</td></tr></tbody></table>

**Websocket URL Request Example**

```url
wss://dev.pulsoid.net/api/v1/data/real_time?access_token=8c4da3ce-7ed7-4a19-a1f1-058498661e45
```

**WebSocket Message Example**

```json
{
  "measured_at": 1625310655000,
  "data": {
    "heart_rate": 40
  }
}
```

**Websocket URL Request Example With response\_mode=text\_plain\_only\_heart\_rate**

```uri
wss://dev.pulsoid.net/api/v1/data/real_time?access_token=8c4da3ce-7ed7-4a19-a1f1-058498661e45&response_mode=text_plain_only_heart_rate
```

**WebSocket Message Example With response\_mode=text\_plain\_only\_heart\_rate**

```json
123
```

***

#### JavaScript / TypeScript

For JavaScript and TypeScript applications, use the official [`@pulsoid/socket`](https://www.npmjs.com/package/@pulsoid/socket) library instead of managing WebSocket connections manually. It provides auto-reconnection with exponential backoff, typed events, and zero dependencies.

```bash
npm install @pulsoid/socket
```

```javascript
import PulsoidSocket from '@pulsoid/socket';

const socket = PulsoidSocket.create('YOUR_TOKEN');

socket.on('heart-rate', (data) => {
  console.log(`${data.heartRate} BPM`);
});

await socket.connect();
```

See the [GitHub repository](https://github.com/pulsoid-oss/pulsoid-socket) for full documentation and configuration options.


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.pulsoid.net/read-heart-rate/read-heart-rate-via-websocket.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
