I am having trouble in a meteor project. I am trying to add a email address to a subscriber list using the campaign monitor api. I am using a npm package called createsend-node, it is a wrapper of the api. I have successfully added a subscriber to a list using the api, however when I try to fire a meteor server method from a form submit event the api kicks back a email address not valid response code 1
. I will include my code below. When I added the subscriber manually without the method it is successful. The email address was a string when I passed it manually, which is the same for the method. Code Below.
html
<template name="info">
<h2>Signup For Our Newsletter</h2>
<form id="cm-subscribe">
<input field name="email" type="email" value="email">
<input field name="name" type="text" value="name">
<input type="submit">
</form>
</template>
Client side js
Template.info.events({
'submit #cm-subscribe'(event){
event.preventDefault();
var form = event.target;
var email = form.email.value;
var name = form.name.value;
console.log(email + " / " + name);
Meteor.call('addSub', email, name);
}
});
Server side js
Meteor.methods({
addSub: function (name, email) {
console.log(name);
console.log(email);
var listId = 'someid' // The ID of the list
var details = {
EmailAddress: email,
Name: name,
CustomFields: [
{ Key: 'CustomKey', Value: 'Some Value' }
]
};
api.subscribers.addSubscriber(listId, details, (err, res) => {
if (err) console.log(err);
});
}
});
You've reversed the arguments between the caller and the method.
Meteor.call('addSub', email, name)
Meteor.methods({
addSub: function (name, email) {