# Notification

## Notification APIs

The Notification APIs play a crucial role in delivering real-time notifications to users within the e-commerce application. These APIs leverage Firebase integration to handle notification management efficiently. There are three essential endpoints involved in the notification system:

<figure><img src="https://3686328336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fd1Iq7THDAagTQzeC9rTN%2Fuploads%2FTRwAJYSPBxQUL1qF2X6A%2Fimage.png?alt=media&#x26;token=f8f99ec4-ecd0-4ae4-b7da-c073dcc32e4f" alt=""><figcaption><p><strong>Notification interface</strong></p></figcaption></figure>

### Get Notifications API

The Get Notifications API retrieves a list of all notifications for the authenticated user. It provides information about various notifications, including messages, promotions, order updates, and more.

**Endpoint**

* **`{{baseurl}}/api/v1/get-notifications`**

**Method**&#x20;

* **GET**

**Request Parameters:**

* `lang_code` (optional): A two-letter language code (e.g., "en" for English, "es" for Spanish, etc.) to support language-based localization. If provided, the API returns category names and descriptions in the specified language.
* `page` (optional): The page number to retrieve when using pagination. If not specified, the API defaults to the first page.
* `limit` (optional): The maximum number of categories to return per page. If not specified, the API defaults to 15 categories per page.

**Request Body:**

* None

**Authorization:** The API requires a bearer token in the request header for authentication. Users need to include their valid bearer token in the "Authorization" header of the HTTP request to access their notifications.

**Response Format:** The API responds with a JSON array containing notification objects. Each notification object represents a specific notification and contains details such as title, content, type, timestamp, and more.

````json
{
    "success": true,
    "data": {
        "notifications": [
            
            {
                "id": 17,
                "title": "click on bundle 20% off on all product click now",
                "content": "Get 30% off on all products",
                "image": null,
                "created_at": "2023-07-28 15:40:46",
                "api_hit": "2023-08-04 20:50:55",
                "is_read": true
            },
      
            {
                "id": 13,
                "title": "test",
                "content": "testing",
                "image": "https://majarat-developemt.s3.ap-southeast-1.wasabisys.com/uploads/all/MicrosoftTeams-image%20%284%29.png",
                "created_at": "2023-07-07 07:54:59",
                "api_hit": "2023-08-04 20:50:55",
                "is_read": true
            },
            {
                "id": 9,
                "title": "Sale",
                "content": "big sale",
                "image": "https://majarat-developemt.s3.ap-southeast-1.wasabisys.com/uploads/all/download.jpeg",
                "created_at": "2023-05-31 11:17:53",
                "api_hit": "2023-08-04 20:50:55",
                "is_read": true
            },
            {
                "id": 5,
                "title": "Rush hour sale",
                "content": "Get 30% off on all products",
                "image": "https://majarat-developemt.s3.ap-southeast-1.wasabisys.com/uploads/all/verified.png",
                "created_at": "2023-05-12 09:26:38",
                "api_hit": "2023-08-04 20:50:55",
                "is_read": true
            }
        ],
        "pagination": {
            "total": 13,
            "count": 13,
            "limit": 15,
            "current_page": 1,
            "total_pages": 1
        }
    },
    "message": "Success",
    "status_code": 200
```
````

#### 2. Unread Notifications API

The Unread Notifications API retrieves a list of unread notifications for the authenticated user. It allows users to stay updated on new notifications they haven't seen yet.

**Endpoint**

* **`{{baseurl}}/api/v1/unread-notifications`**

**Method**

* **GET**

**Request Parameters:**

* None

**Request Body:**

* None

**Authorization:** The API requires a bearer token in the request header for authentication. Users need to include their valid bearer token in the "Authorization" header of the HTTP request to access their unread notifications.

**Response Format:** The API responds with a JSON array containing unread notification objects. Each object represents a specific unread notification and includes details such as title, content, type, timestamp, and more.

```json

{
    "success": true,
    "message": "success",
    "data": 0,
    "status_code": 200
}

```

#### 3. Device Token API

The Device Token API is used during the registration process to associate a user's device token from Firebase Cloud Messaging (FCM) with their account. This enables the e-commerce application to send personalized notifications directly to the user's device.

**Endpoint**

* **`{{baseurl}}/api/v1/offers/customer/device_token`**

**Method**

* **POST**

**Request Parameters:**

* None

**Request Body:** The request body should include the user's device token obtained from Firebase as follows:

```json
{
  "device_token": "your_device_token_here"
}
```

**Authorization:** The API requires a bearer token in the request header for authentication. Users need to include their valid bearer token in the "Authorization" header of the HTTP request to link their device token with their account.

**Response Format:** The API responds with a success message or appropriate status code indicating that the device token has been successfully associated with the user's account.

```json
{
    "success": true,
    "message": "Success",
    "status_code": 200
}
```

#### Features:

* The Get Notifications API allows users to fetch all notifications they have received, including promotions, updates, and messages.
* The Unread Notifications API helps users find unread notifications quickly, ensuring they stay up-to-date with the latest information.
* The Device Token API enables users to link their device token from Firebase Cloud Messaging with their account, allowing personalized notifications.

#### Usage:

* The Get Notifications API is used to display the user's notification history, ensuring they can access previous notifications whenever needed.
* The Unread Notifications API is used to provide users with a dedicated section for unread notifications, ensuring they don't miss any important updates.
* The Device Token API is called during the registration process to associate the user's device token, enabling the delivery of personalized notifications.

#### Best Practices:

* Implement proper error handling to handle scenarios where there are no notifications or unread notifications available.
* Securely store and handle device tokens to ensure user privacy and data security.

#### Importance:

The Notification APIs are vital for engaging users effectively and keeping them informed about promotions, order updates, and other essential information. By integrating with Firebase Cloud Messaging, the e-commerce application can deliver personalized and timely notifications to users, increasing user engagement and driving repeat visits and purchases. The use of bearer tokens ensures secure and authenticated access to notifications, protecting sensitive user data and maintaining the integrity of the notification system.
