# Notify user is watching a video

`POST /api/v1/videos/{id}/views`

Call this endpoint regularly (every 5-10 seconds for example) to notify the server the user is watching the video. After a while, PeerTube will increase video's viewers counter. If the user is authenticated, PeerTube will also store the current player time.

Authentication: no security requirement declared for this operation.

Parameters:

- `id` (path, id | UUIDv4 | shortUUID, required) - The object id, uuid or short uuid
  Type: id | UUIDv4 | shortUUID
  
  oneOf:
    Reference: [id](https://sourcey-peertube.pages.dev/api-rest-reference/models/id.md); Type: id
    
    minimum: 1
    
    Example:
    
    ```json
    42
    ```
  
    Reference: [UUIDv4](https://sourcey-peertube.pages.dev/api-rest-reference/models/uuidv4.md); Type: UUIDv4, uuid
    
    minLength: 36
    
    maxLength: 36
    
    pattern: "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
    
    Example:
    
    ```json
    "9c9de5e8-0a1e-484a-b099-e80766180a6d"
    ```
  
    Reference: [shortUUID](https://sourcey-peertube.pages.dev/api-rest-reference/models/shortuuid.md); Type: shortUUID
    
    translation of a uuid v4 with a bigger alphabet to have a shorter uuid
    
    Example:
    
    ```json
    "2y84q2MQUMWPbiEcxNXMgC"
    ```

Request body: application/json (required)

Type: UserViewingVideo

Schema: [UserViewingVideo](https://sourcey-peertube.pages.dev/api-rest-reference/models/userviewingvideo.md)

- `currentTime` (required)
  Type: integer, seconds
  
  timestamp within the video, in seconds
  
  Example:
  
  ```json
  5
  ```

- `viewEvent` (optional)
  Type: string
  
  Event since last viewing call:
   * `seek` - If the user seeked the video
  
  
  enum: ["seek"]

- `sessionId` (optional)
  Type: string
  
  Optional param to represent the current viewer session. Used by the backend to properly count one view per session per video. PeerTube admin can configure the server to not trust this `sessionId` parameter but use the request IP address instead to identify a viewer.
  

- `client` (optional)
  Type: string
  
  Client software used to watch the video. For example "Firefox", "PeerTube Approval Android", etc.
  

- `device` (optional)
  Type: VideoStatsUserAgentDevice
  
  Device used to watch the video. For example "desktop", "mobile", "smarttv", etc.
  
  
  allOf:
    Reference: [VideoStatsUserAgentDevice](https://sourcey-peertube.pages.dev/api-rest-reference/models/videostatsuseragentdevice.md); Type: VideoStatsUserAgentDevice
    
    enum: ["console","embedded","mobile","smarttv","tablet","wearable","xr","desktop"]

- `operatingSystem` (optional)
  Type: string
  
  Operating system used to watch the video. For example "Windows", "Ubuntu", etc.
  

Responses:

- 204: successful operation

## Examples

### cURL

```bash
curl -X POST 'https://peertube2.cpy.re/api/v1/videos/42/views' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "currentTime": 5,
  "viewEvent": "seek",
  "sessionId": "string",
  "client": "string",
  "operatingSystem": "string"
}'
```

### JavaScript

```javascript
const body = `{
  "currentTime": 5,
  "viewEvent": "seek",
  "sessionId": "string",
  "client": "string",
  "operatingSystem": "string"
}`;

const response = await fetch('https://peertube2.cpy.re/api/v1/videos/42/views', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body,
});

const data = await response.text();
```

### Python

```python
import requests

body = '''{
  "currentTime": 5,
  "viewEvent": "seek",
  "sessionId": "string",
  "client": "string",
  "operatingSystem": "string"
}'''

response = requests.post(
    'https://peertube2.cpy.re/api/v1/videos/42/views',
    data=body.encode('utf-8'),
    headers={
        'Content-Type': 'application/json',
    },
)
print(response.text)
```
