User Notifications APIs
There will be maximum 20 latest notifications stored for each user. If more new notifications get generated, the latest ones will replace the oldest ones regardless of if the user have seen them or not.
Both APIs require the session-token cookie header to sent along.
There are also 2 APIs for handling the user notifications:
- Get Notifications: This API will return 20 latest notifications each time which will be divided into a few categories (more on categories later below).
- Update Notification Status: This API will update the
seenstatus of the notifications based on what category notifications are opened by the user.
There will be 4 notfication categories as given below:
- account
- primary
- reward
- order
category property having one of the above category value.1. Get User Notifications
Endpoint
GET /user/notifications/get
Response
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{
"success": true,
"notification_data": {
"_id": "65ddb74ad5d42b2477361d98",
"user_id": "65ddb7496a09ca290bec88b2",
"__v": 0,
"createdAt": "2024-02-27T10:19:54.298Z",
"notifications": [
{
"category": "account",
"heading": "Login",
"message": "You logged in to your Urban Fits account through Windows10/Opera at 21-6-2024 12:41",
"mini_msg": "You logged in to your Urban Fits account at 21-6-2024 12:41",
"seen": false,
"timestamp": "2024-06-21T07:41:07.356Z",
"_id": "66752e9335c91168eaed1d79"
},
{
"category": "account",
"heading": "Login",
"message": "You logged in to your Urban Fits account through Windows10/Chrome at 21-6-2024 7:35",
"mini_msg": "You logged in to your Urban Fits account at 21-6-2024 7:35",
"seen": false,
"timestamp": "2024-06-21T07:35:26.472Z",
"_id": "66752d3f02248364f6173e14"
},
{
"category": "reward",
"heading": "Congratulations!!",
"message": "You have won a lot of points",
"mini_msg": "You have won a lot of points",
"seen": true,
"timestamp": "2024-05-25T15:23:44.656Z",
"_id": "66520280d505188bced40359"
},
// And so on...
],
"updatedAt": "2024-06-21T07:41:07.359Z"
}
}2. Update Notifications Seen Status
Endpoint
PUT /user/notifications/update
Payload
This API will be needing just a url query parameter of category name. Specify a category whose notifications status you want to update to seen. For instance the user opened the account category notifications from the client then to update all the account category notifications to seen status, the url will be like this:
1
/user/notifications/update?category=accountResponse
The whole updated notifications object won't be returned in the response. You will have to update it manually on the client side to seen status as soon as user opens the notifications from inbox for a better and fast UX.
1
2
3
4
{
success: true,
msg: "Notifications of acccount categroy status updated to seen"
}Although for receiving the real time notifications, you need to set up the Pusher Client SDK. Please first refer to the Socket Setup before moving further.
Here are few more important things about some of the notification object properties to keep in mind:
headingThe heading property is the short title to display with the actual notificaiton message.mini_msgThe mini_msg property will have a short and concise message to show in the in app toast notifications for a compact and clean UI.messageThis will be the detailed message about any action or operation describing it in detail. It can as short as one line and as long as a paragraph. So avoid showing this message in toasters.hrefThis is a hyper referance url, an optional property. Only some of the notifications will have it. Embed this link with the notifications in the app who have this.
The notification data you will receive in the new-notification event will have 2 mandatory properties and 1 optional property. The property names and there information is given below:
notify:Mandatory| This is a boolean property which will tell whether to show the notification in the toast or not. If its false then you just have to store it along with other inbox notifications, skipping the display of it in a notification toast.notification_data:Mandatory| This will be the notification data object containing all the necessary properties.user_data:Optional| This user data object will be sent when there's an update occured in the user's data. On getting this data, update the user data in the app.