ActiveCampaign / activecampaign-api-nodejs

Node.js wrapper for the ActiveCampaign API
MIT License
39 stars 36 forks source link

Adding contact to List #39

Closed MikeVerhees closed 7 years ago

MikeVerhees commented 7 years ago

Hello,

I'm trying to add new members to my contacts and a specific mailing list, however all the examples I could find were for PHP. So I tried to structure it the same way as Lists are gotten from a GET request, I didn't get an error, but no success adding the user to the list:

this is what I've been trying:

var lists = {'5': 5};
            var status = {'5': 1};
            var contact = {
                email: user.email
                ,p: lists
                ,status: status
            };

// Add contact
            var post_test = ac.api("contact/add", contact).then(function (result) {
                // successful request
                console.log(result);
            }, function (result) {
                console.log("ERROR",result);
                // request error
            });

I'd appreciate any help or pointers in the right direction, Thanks!

Webaholicson commented 7 years ago

Make sure the list exists in the account. Also I don't see the user var being declared anywhere in the code. I was able to do it with the following code:

var ActiveCampaign = require("activecampaign");

var ac = new ActiveCampaign("URL", "API_KEY");

var user = {
    email: 'john@example.com'
}

var contact = {
    'email': user.email,
    'p[2]': 2,
    'status[2]': 1,
};

var contact_add = ac.api("contact/add", contact);

contact_add.then(function(result) {
    console.log(result);
}, function(result) {
    console.log(result);
});
thebkr7 commented 5 years ago

Also to just add a note for any future readers, to find the list Id which is the 'p[2]': 2, part of the contact variable. You need to open the Active Campaign list in your browser and the list Id for the list is in the url. So if you list is #46 it would look like: var contact = { 'email': user.email, 'p[2]': 46, 'status[2]': 1, };

hphirke commented 5 years ago

I need to add multiple contacts to a list, Can I do that in one call using v1 or v3? OR Do I need to call 1 API call per contact?