Billing error while deploying cloud functions onDocumentCreated trigger with v2 api for cloud functions.
I tried to deploy the below function, got this error:”Write access to project ‘xxxxx’ was denied: please check billing account associated and retry“**. Not sure why it does not let me when I can easily upload V1 functions.
const { onDocumentCreated } = require("firebase-functions/v2/firestore");
const { getMessaging } = require('firebase-admin/messaging');
const { initializeApp } = require('firebase-admin/app');
initializeApp();
exports.sendNotificationOnSales = onDocumentCreated('sales/{docId}', async (event) => {
const newData = event.data.data();
const itemName=newData['Item name'];
const itemPrice=newData['Price'];
const message = {
topic: 'sale',
notification: {
title: 'New item for sale has been added',
body: `${itemName} ${itemPrice}`,
},
};
try {
await getMessaging().send(message);
console.log('Notification sent successfully');
} catch (error) {
console.error('Error sending notification:', error);
}
});