Skip to main content

Mark notification as read

PUT 

/company/read/:id

Updates the status of a notification to mark it as read, recording the current date/time.

Use Cases:

  • When a user opens/clicks a notification
  • Synchronization between devices when reading notifications
  • Bulk update of notification status
  • Integration with activity tracking systems

Typical Flow:

  1. The client detects interaction with a notification (click, view in UI)
  2. Validates that the notification belongs to the current user
  3. Calls this endpoint with the notification ID
  4. The server:
    • Validates the JWT token
    • Verifies that the notification exists and belongs to the user's company
    • Updates the isRead field to true
    • Sets readedAt with the current date/time
  5. Returns the updated notification
  6. The client updates the UI locally

Considerations:

  • Only notifications belonging to the user's company can be marked
  • The operation is idempotent (multiple calls with the same ID cause no side effects)
  • The readedAt field is set with the server's date/time, not the client's

Implementation Example:

// Example call from frontend
async function markNotificationAsRead(notificationId) {
try {
const response = await fetch(`/company/notifications/read/${notificationId}`, {
method: 'PUT',
headers: {
'Authorization': `Bearer ${userToken}`,
'Content-Type': 'application/json'
}
});

if (response.ok) {
const updatedNotification = await response.json();
updateNotificationInUI(updatedNotification);
}
} catch (error) {
console.error('Error marking notification as read:', error);
}
}

Request

Responses

Notification marked as read.