I'm trying to create a campaign in Firebase using the Admin SDK for Node.js. However, when I try to call the createCampaign() method under admin.messaging(), I get an error that says it doesn't exist. Here's the relevant code:
const admin = require('firebase-admin');
admin.initializeApp({
credential: admin.credential.cert("serviceAccountKey.json"),
});
exports.createMessageCampaign = functions.firestore
.document("/documents/{documentId}")
.onUpdate(async (change, context) => {
const campaign = {
name: 'my-campaign',
message: {
notification: {
title: 'New products!',
body: 'Check out our latest products!'
}
},
schedule: {
startTime: '2023-05-05T09:00:00Z',
endTime: '2023-05-10T18:00:00Z'
}
};
admin.messaging().createCampaign(campaign)
.then((response) => {
console.log('Campaign created:', response);
}).catch((error) => {
console.error('Error creating campaign:', error);
});
});
Does anyone know another way to create a campaign using functions? Thanks