# Push Notifications API ###### tags: API ## Technologies * nodejs * nestjs framework (https://nestjs.com/) * firebase Library (https://www.npmjs.com/package/firebase) * mongodb ## Collections ### devices ``` { _id: MongoID, userId: string, device: { id: string, os: string, token: string }, meta: any, record: { state: string, createdAt: Date, updatedAt: Date } } ``` ## API ## Create **API Endpoint** ``` POST https://{baseUrl}/v1/device ``` **Request Body** ```json= { data: { userId: "5f5efa4d1275eb00190abc6a", device: { id: "", os: "", token: "" }, meta: any } } ``` **Response Body - Success** ```json= { result: { data: { _id: "5f9195f8dbbae6d97664622a", userId: "5f5efa4d1275eb00190abc6a", device: { id: "", os: "", token: "" }, meta: any, record: { state: "active", createdAt: "01-11-2021 12:49", updatedAt: null } } } } ``` **Response Body - Failed** ```json= { errors: [ { "keyword": "userId_required" }, { "keyword": "token_required" } ] } ``` ## Get **API Endpoint** ``` GET https://{baseUrl}/v1/device/{id} ``` ## Update **API Endpoint** ``` PUT https://{baseUrl}/v1/device/{id} ``` **Request Body** ```json= { data: { userId: "5f5efa4d1275eb00190abc6a", device: { id: "", os: "", token: "" }, meta: any, record: { state: "active" } } } ``` ## Soft Delete **API Endpoint** ``` DELETE https://{baseUrl}/v1/device/{id}/soft ``` ## Search **API Endpoint** ``` POST https://{baseUrl}/v1/devices ``` **Request Body** ```json= { data: { userId: "5f5efa4d1275eb00190abc6a", device: { id: "", os: "", token: "" }, }, paging: { page: 1, size: 20 }, sort: [{ property: "keyword", direction: "ASC" }] } ``` **Response Body - Success** ```json= { result: { data: [{}, {}, {}], page: { total: 56, number: 1, size: 20 } } } ``` ## notify to device **API Endpoint** ``` POST https://{baseUrl}/v1/device/{id}/notify ``` **Request Body** ```json= { data: { type: "", title: "", sound: "", text: "" } } ``` **Response - Success** ``` HTTP STATUS 200 OK ``` ## notify to user **API Endpoint** ``` POST https://{baseUrl}/v1/user/{id}/notify ``` **Request Body** ```json= { data: { type: "", title: "", sound: "", text: "" } } ``` **Response - Success** ``` HTTP STATUS 200 OK ```