Mark Notification as Read (Admin)
Mark a specific notification as read.
Endpoint
Authentication
Required: Admin authentication token
Request
Headers
Body
Request Fields
| Field | Type | Required | Description |
|---|---|---|---|
id |
integer | Yes | ID of the notification to mark as read |
Response
Success (200 OK)
Error (400 Bad Request)
Missing id:
Invalid id:
Error (404 Not Found)
Notification doesn't exist or doesn't belong to you:
Error (401 Unauthorized)
Error (403 Forbidden)
Example Usage
JavaScript/Fetch
async function markNotificationRead(notificationId) {
const response = await fetch('/v1/chat/admin/notifications/read/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Token ${adminToken}`
},
body: JSON.stringify({
id: notificationId
})
});
const data = await response.json();
if (data.success) {
console.log('Notification marked as read');
// Update UI - decrement badge count
updateNotificationBadge();
}
}
Axios
import axios from 'axios';
const markNotificationRead = async (notificationId) => {
try {
await axios.post('/v1/chat/admin/notifications/read/',
{ id: notificationId },
{
headers: {
'Authorization': `Token ${adminToken}`
}
}
);
console.log('Notification marked as read');
} catch (error) {
console.error('Failed to mark notification as read:', error);
}
};
cURL
curl -X POST "http://localhost:8000/v1/chat/admin/notifications/read/" \
-H "Content-Type: application/json" \
-H "Authorization: Token your_admin_token_here" \
-d '{
"id": 45
}'
Usage in UI
React Component
import { useState } from 'react';
import axios from 'axios';
function NotificationItem({ notification, onRead }) {
const [isRead, setIsRead] = useState(notification.is_read);
const handleClick = async () => {
// Navigate to chat session
navigate(`/dashboard/messages?session=${notification.session_id}`);
// Mark as read
if (!isRead) {
try {
await axios.post('/v1/chat/admin/notifications/read/',
{ id: notification.id },
{ headers: { 'Authorization': `Token ${adminToken}` } }
);
setIsRead(true);
onRead(notification.id); // Update parent component
} catch (error) {
console.error('Failed to mark as read:', error);
}
}
};
return (
<div
className={`notification ${isRead ? 'read' : 'unread'}`}
onClick={handleClick}
>
<img src={notification.store_logo} alt={notification.store_name} />
<div>
<strong>{notification.store_name}</strong>
<p>{notification.content}</p>
<span>{formatTime(notification.created_at)}</span>
</div>
</div>
);
}
Batch Mark as Read
async function markMultipleNotificationsRead(notificationIds) {
const promises = notificationIds.map(id =>
axios.post('/v1/chat/admin/notifications/read/',
{ id },
{ headers: { 'Authorization': `Token ${adminToken}` } }
)
);
try {
await Promise.all(promises);
console.log('All notifications marked as read');
} catch (error) {
console.error('Some notifications failed to mark as read:', error);
}
}
Notes
- This endpoint marks a single notification as read
- The notification's
is_readfield is set totrue - The notification remains in the database but won't count towards unread count
- You can only mark your own notifications as read (checked by
admin_id) - To mark all notifications as read at once, use Mark All Notifications Read
Typical Workflow
- User clicks on a notification
- Navigate to the chat session
- Call this endpoint to mark the notification as read
- Update the notification badge count
- Remove the unread indicator from the notification UI
When to Call This Endpoint
- When user clicks on a notification
- When user views the chat session from a notification
- When notification is displayed in a focused state
Performance Considerations
- For marking many notifications, consider using Mark All Notifications Read
- Batch requests when marking multiple notifications (use
Promise.all) - Update UI optimistically (don't wait for server response)
Related Endpoints
- Get Notifications - Get all notifications
- Get Notification Count - Get unread count
- Mark All Notifications Read - Mark all as read
- Admin WebSocket - Real-time updates