MikelCalvo / node-mailwizz

[UNOFFICIAL] MailWizz API for NodeJS
https://npmjs.org/package/node-mailwizz
ISC License
10 stars 14 forks source link

Node API to create a new subscriber #62

Open chengtie opened 6 months ago

chengtie commented 6 months ago

I tried to use the following code to create a new subscriber aoxiang.paris.new@gmail.com (I'm sure it does not exist in the list):

const { ListSubscribers } = require('node-mailwizz');

const config = {
    publicKey: 'key',
    secret: 'key',
    baseUrl: 'http://mail.mycompany.com/api'
}

const subscribers = new ListSubscribers(config);

function createSubscriber() {
    const userInfo = { EMAIL: "aoxiang.paris.new@gmail.com", TRANSACTIONAL_REMINDERS: "YES" };
    subscribers.create({
        listUid: "en804x0lnrf1f",
        data: userInfo
    }).then(result => {
        console.log('Subscriber created:', result);
    }).catch(err => {
        console.error('Error:', err);
    })
}

createSubscriber();

It returned

Error: {
  status: 'error',
  error: 'Only POST requests allowed for this endpoint.'
}

Does anyone know what's the correct way to create a new subscriber by API in node?