0

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

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
yonatan
  • 23
  • 1
  • 10
  • There is no public API to create messaging campaigns. I've never seen a `createCampaign ` API call either. What made you think that a `createCampaign` exists? – Frank van Puffelen May 04 '23 at 00:49
  • I asked chatgpt (I know it's not the most reliable tool) and it says there was a function to create a campaign in firebase-admin 9.x Anyway, I looked at what the library exporting and saw that it exports send messages commands and not create new campaign You wrote that there is no public API, which means I can't create/update a campaign in any automatic way? – yonatan May 04 '23 at 06:15

0 Answers0