简体   繁体   中英

How to send push notification from Rest API

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

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"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM