> ## Documentation Index
> Fetch the complete documentation index at: https://cloud-docs.mentra.glass/llms.txt
> Use this file to discover all available pages before exploring further.

# User Data

> REST endpoints for managing user data and settings

## Set DateTime

Update the user's datetime setting and notify subscribed apps.

### Endpoint

<CodeGroup>
  ```bash Production theme={null}
  POST https://api.mentra.glass/api/user-data/set-datetime
  ```

  ```bash Development theme={null}
  POST https://devapi.mentra.glass/api/user-data/set-datetime
  ```

  ```bash Local theme={null}
  POST http://localhost:8002/api/user-data/set-datetime
  ```
</CodeGroup>

### Request Body

```json theme={null}
{
  "coreToken": "eyJhbGciOiJIUzI1NiIs...",
  "datetime": "2024-01-20T10:30:00Z"
}
```

<Note>
  The datetime must be in ISO 8601 format.
</Note>

### Response

Success (200):

```json theme={null}
{
  "success": true,
  "userId": "user@example.com",
  "datetime": "2024-01-20T10:30:00Z"
}
```

Error (400):

```json theme={null}
{
  "error": "Missing or invalid coreToken or datetime (must be ISO string)"
}
```

Error (401):

```json theme={null}
{
  "error": "Invalid core token - missing user email" // or "Invalid or expired core token"
}
```

Error (404):

```json theme={null}
{
  "error": "User session not found"
}
```

### Implementation

* **File**: `packages/cloud/src/routes/user-data.routes.ts:17-70`
* **Authentication**: JWT token validation using `AUGMENTOS_AUTH_JWT_SECRET`
* **Side Effects**: Sends CUSTOM\_MESSAGE to all apps subscribed to custom messages

### Custom Message Format

Apps subscribed to `CUSTOM_MESSAGE` stream will receive:

```json theme={null}
{
  "type": "CUSTOM_MESSAGE",
  "action": "update_datetime",
  "payload": {
    "datetime": "2024-01-20T10:30:00Z",
    "section": "topLeft"
  },
  "timestamp": "2024-01-20T10:30:00.000Z"
}
```

### Usage Notes

* The coreToken is passed in the request body rather than as a header
* This endpoint stores the datetime in the user's session as `userDatetime`
* Only apps that have subscribed to the `CUSTOM_MESSAGE` stream type will receive the update
* The datetime is used for display purposes on the glasses

## Error Codes

| Code | Description                                                         |
| ---- | ------------------------------------------------------------------- |
| 400  | Missing or invalid parameters                                       |
| 401  | Invalid or expired core token                                       |
| 404  | User session not found - user must have active WebSocket connection |
