Skip to content

Get Notification by ID

Retrieve a specific notification by its unique identifier.

Endpoint

http
GET /notifications/notifications/:id

Authentication: Required (JWT)

Path Parameters

ParameterTypeRequiredDescription
idstringYesNotification unique identifier (MongoDB ObjectId)

Request Example

bash
curl http://localhost:3000/notifications/notifications/507f1f77bcf86cd799439011 \
  -H "Authorization: Bearer <access_token>"

Response

Status Code: 200 OK

json
{
  "id": "507f1f77bcf86cd799439011",
  "userId": "507f1f77bcf86cd799439010",
  "contestId": "507f1f77bcf86cd799439012",
  "type": "CONTEST_REMINDER",
  "title": "Contest Starting Soon",
  "message": "Codeforces Round #900 starts in 2 hours",
  "payload": {
    "contestName": "Codeforces Round #900",
    "platform": "codeforces",
    "startTime": "2024-02-16T14:35:00.000Z",
    "hoursUntilStart": 2,
    "contestUrl": "https://codeforces.com/contest/1900"
  },
  "channels": ["email", "push"],
  "status": "SENT",
  "deliveryStatus": [
    {
      "channel": "email",
      "status": "SENT",
      "sentAt": "2024-02-16T12:35:00.000Z",
      "retryCount": 0
    },
    {
      "channel": "push",
      "status": "SENT",
      "sentAt": "2024-02-16T12:35:05.000Z",
      "retryCount": 0
    }
  ],
  "scheduledAt": "2024-02-16T12:35:00.000Z",
  "sentAt": "2024-02-16T12:35:00.000Z",
  "isRead": false,
  "createdAt": "2024-02-16T12:30:00.000Z",
  "updatedAt": "2024-02-16T12:35:05.000Z"
}

Response Fields

FieldTypeDescription
idstringNotification unique identifier
userIdstringUser who received the notification
contestIdstringRelated contest ID (optional)
typestringNotification type
titlestringNotification title
messagestringNotification message
payloadobjectAdditional notification data
channelsarrayDelivery channels used
statusstringOverall notification status
deliveryStatusarrayPer-channel delivery details
scheduledAtstringWhen notification was scheduled
sentAtstringWhen notification was sent
failedAtstringWhen notification failed (if applicable)
isReadbooleanWhether notification was read
readAtstringWhen notification was read
createdAtstringCreation timestamp
updatedAtstringLast update timestamp

Notification Types

TypeDescription
CONTEST_REMINDERContest starting within notification window
CONTEST_STARTINGContest is about to start
CONTEST_ENDINGContest is about to end
SYSTEM_ALERTSystem-wide announcements

Notification Status

StatusDescription
PENDINGNotification queued for delivery
SENTSuccessfully delivered
FAILEDDelivery failed
RETRYINGRetry in progress

Delivery Status

Each channel has its own delivery status:

json
{
  "channel": "email",
  "status": "SENT",
  "sentAt": "2024-02-16T12:35:00.000Z",
  "failedAt": null,
  "error": null,
  "retryCount": 0
}

Delivery Status Fields

FieldTypeDescription
channelstringNotification channel: email, whatsapp, push
statusstringChannel-specific status
sentAtstringWhen notification was sent via this channel
failedAtstringWhen delivery failed (if applicable)
errorstringError message (if failed)
retryCountnumberNumber of retry attempts

Error Responses

404 Not Found

json
{
  "error": "Notification not found"
}

401 Unauthorized

json
{
  "statusCode": 401,
  "message": "Unauthorized",
  "error": "Unauthorized"
}

400 Bad Request

json
{
  "statusCode": 400,
  "message": "Invalid notification ID format",
  "error": "Bad Request"
}

Use Cases

  1. Notification Details: View complete notification information
  2. Delivery Tracking: Check delivery status across channels
  3. Debugging: Investigate notification issues
  4. User Interface: Display notification details in UI
  5. Retry Logic: Check status before retrying failed notifications

Example: Failed Notification

json
{
  "id": "507f1f77bcf86cd799439011",
  "userId": "507f1f77bcf86cd799439010",
  "type": "CONTEST_REMINDER",
  "status": "FAILED",
  "deliveryStatus": [
    {
      "channel": "email",
      "status": "FAILED",
      "failedAt": "2024-02-16T12:35:00.000Z",
      "error": "Invalid email address",
      "retryCount": 3
    }
  ],
  "isRead": false,
  "createdAt": "2024-02-16T12:30:00.000Z"
}

Best Practices

✅ Do

  • Check notification status before retrying
  • Use delivery status to identify channel-specific issues
  • Cache notification details when displaying in UI
  • Handle 404 errors gracefully

❌ Don't

  • Poll this endpoint repeatedly for status updates
  • Ignore delivery status errors
  • Assume notification exists without error handling

Built with ❤️ for competitive programmers worldwide.