Skip to content

Get Notification History

Retrieve notification history with filtering and pagination.

Endpoint

http
GET /notifications/notifications

Authentication: Required (JWT)

Query Parameters

ParameterTypeRequiredDefaultDescription
userIdstringNo-Filter by user ID
statusstringNo-Filter by status: PENDING, SENT, FAILED, RETRYING
typestringNo-Filter by type: CONTEST_REMINDER, CONTEST_STARTING, CONTEST_ENDING, SYSTEM_ALERT
startDatestringNo-Filter from date (ISO 8601)
endDatestringNo-Filter to date (ISO 8601)
pagenumberNo1Page number
limitnumberNo20Items per page (max: 100)

Request Example

bash
curl "http://localhost:3000/notifications/notifications?userId=507f1f77bcf86cd799439011&status=SENT&page=1&limit=20" \
  -H "Authorization: Bearer <access_token>"

Response

Status Code: 200 OK

json
{
  "notifications": [
    {
      "id": "507f1f77bcf86cd799439012",
      "userId": "507f1f77bcf86cd799439011",
      "contestId": "507f1f77bcf86cd799439013",
      "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
      },
      "channels": ["email"],
      "status": "SENT",
      "deliveryStatus": [
        {
          "channel": "email",
          "status": "SENT",
          "sentAt": "2024-02-16T12:35:00.000Z",
          "retryCount": 0
        }
      ],
      "isRead": false,
      "createdAt": "2024-02-16T12:35:00.000Z",
      "updatedAt": "2024-02-16T12:35:00.000Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 150,
    "totalPages": 8
  }
}

Response Fields

Notification Object

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

Pagination Object

FieldTypeDescription
pagenumberCurrent page number
limitnumberItems per page
totalnumberTotal number of notifications
totalPagesnumberTotal number of pages

Filter Examples

By Status

bash
curl "http://localhost:3000/notifications/notifications?status=FAILED" \
  -H "Authorization: Bearer <token>"

By Type

bash
curl "http://localhost:3000/notifications/notifications?type=CONTEST_REMINDER" \
  -H "Authorization: Bearer <token>"

By Date Range

bash
curl "http://localhost:3000/notifications/notifications?startDate=2024-02-01T00:00:00Z&endDate=2024-02-28T23:59:59Z" \
  -H "Authorization: Bearer <token>"

Multiple Filters

bash
curl "http://localhost:3000/notifications/notifications?userId=123&status=SENT&type=CONTEST_REMINDER&page=2&limit=50" \
  -H "Authorization: Bearer <token>"

Error Responses

400 Bad Request

json
{
  "statusCode": 400,
  "message": "Invalid query parameters",
  "error": "Bad Request"
}

401 Unauthorized

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

Use Cases

  1. User Dashboard: Display user's notification history
  2. Failed Notifications: Find and retry failed notifications
  3. Analytics: Track notification delivery patterns
  4. Debugging: Investigate notification issues
  5. Audit Trail: Review notification history

Best Practices

✅ Do

  • Use pagination for large result sets
  • Filter by date range to limit results
  • Combine filters for specific queries
  • Cache results when appropriate

❌ Don't

  • Request all notifications without pagination
  • Use very large limit values (max: 100)
  • Poll this endpoint frequently (use webhooks instead)

Built with ❤️ for competitive programmers worldwide.