To send push notification we need
- new url
- access token
- new payload structure
var { google } = require("googleapis"); | |
var MESSAGING_SCOPE = "https://www.googleapis.com/auth/firebase.messaging"; | |
var SCOPES = [MESSAGING_SCOPE]; | |
function getAccessToken() { | |
return new Promise(function (resolve, reject) { | |
var jwtClient = new google.auth.JWT( | |
"[email protected]", | |
null, | |
"put_your_private_key_from_json", | |
SCOPES, | |
null | |
); | |
jwtClient.authorize(function (err, tokens) { | |
if (err) { | |
reject(err); | |
return; | |
} | |
resolve(tokens.access_token); | |
}); | |
}); | |
} | |
getAccessToken().then(function (result) { | |
console.log(result);// copy this access token | |
}); |
curl --location 'https://fcm.googleapis.com/v1/projects/jaya-sales-19fe4/messages:send' \ | |
--header 'Content-Type: application/json' \ | |
--header 'Authorization: Bearer that_access_token' \ | |
--data '{ | |
"message":{ | |
"token":"device-access-token", | |
"data": { | |
"title": "Hello", | |
"body": "World", | |
"channelId": "channelId1", | |
"channelDescription": "channelDescription1", | |
"destination": "https://www.google.com", | |
"notificationId": "123" | |
} | |
} | |
}' |