I'm trying to trigger push notification to iOS via the code below. I have already implemented this and it works fine when I trigger them via the Firebase console. But I am unable to trigger them via cloud functions.
When I run this function I get {"error":{"message":"Bad Request","status":"INVALID_ARGUMENT"}}
Am I missing something here ?
exports.testMessage = functions.https.onCall(() => {
console.log('test message started');
const registrationToken = 'fPxlvSiOYEX6gyGhSb5zZp:APA91bH3Q10Yjmo9Oa0Glx78_EZJQ3LO0B1PPWhfOZkTthOI7aP9uUsvzAq3EmYkfaswWIjsTR57NEKkr8BF2q4UbWH4-C5AqGv_XGvJp5C2EPbQ3cjL4zo0eGcSr3IP0PmSpYLjh1Sm';
var message = {
notification: {
title: 'Test title',
body:'Test body'
},
token: registrationToken // Token is inserted here.
};
return admin.messaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
return { 'message': 'sent' }
}).catch((error) => {
console.log('Error sending message:', error);
return { 'message': 'failed' }
});
})