How to send push notification from Rest API

∥☆過路亽.° 提交于 2020-07-08 00:41:12

问题


I have created my App in Firebase and configured for cloud messaging. When I am sending the notification from Firebase Console, device gets the notification but if I try to send via Rest API (Using PostMan). Then notification not coming to device but the response is showing as Success.

Here is my PostMan request

URI - https://fcm.googleapis.com/fcm/send

Header: Content-Type:application/json Authorization:key=MY_SERVER_KEY

Body: { "data": { "title": "Firebase", "detail": "I am firebase" }, "to" : "MY FCM TOKEN HERE" }

Response : { "multicast_id": 7834540847388366233, "success": 1, "failure": 0, "canonical_ids": 0, "results": [ { "message_id": "0:1532422122326299%ebf5f25ef9fd7ecd" } ] }

I have searched and it seems the way mentioned in documentation is same as I am following Can anyone let me know why it is not working? Thanks


回答1:


I am posting here so as to guide others. As per the guidance of @rv7284, We need to send the data in notification key rather any other key.

So While requesting the body should look like this, Other request parameter like header and all will be same as mentioned in the question.

{ "notification": {
 "title": "Firebase",
 "detail": "I am firebase"
},
 "to" : "YOUR FCM TOKEN"
}


来源:https://stackoverflow.com/questions/51494596/how-to-send-push-notification-from-rest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!