ActiveCampaign / activecampaign-api-nodejs

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

Pass actid, key and email via POST data #9

Closed beda closed 9 years ago

beda commented 9 years ago

I wasn't able to pass in the actid, key and email. Couldn't find it in the documentation.

var eventdata = {
            track_actid: "xxxxxxx",
            track_key: "xxxxxxxxxxxxxxxxxxxx",
            track_email: email,
            "event": "eventname",
            "eventdata": "eventdata"
};
var log_event = ac.api("tracking/log", eventdata);
log_event.then(function (result) {
            // successful request
            console.log(result);
        }, function (result) {
            // request error
 });
mthommes commented 9 years ago

Hi, try this - I just tested and it worked for me:

var eventdata = {
    actid: "",
    key: "",
    event: "nodejs_test",
    eventdata: "test1",
    visit: {email: "test@test.com"}
};

var log_event = ac.api("tracking/log", eventdata);

log_event.then(function(result) {
    // successful request
    console.log("log_event result");
    console.log(result);
}, function(result) {
    // request error
});

Make sure to fill in your actual account ID, key, and contact email address.

beda commented 9 years ago

I enabled debug mode. I do:

ac.credentials_test().then(function (result) {
    // successful request
    if (result.success) {
        var eventdata = {
            actid: "myactid",
            key: "mykey",
            event: "nodejs_test",
            eventdata: "test1",
            visit: {email: "test@test.com"}
        };

        var log_event = ac.api("tracking/log", eventdata);
        log_event.then(function (result) {
            // successful request
            console.log("log_event result");
            console.log(result);
        }, function (result) {
            // request error
        });

    } else {
        // INVALID ACCOUNT
    }
}, function (result) {
    // request error
});

I get this:

debug mode enabled
API request URL: https://trackcmp.net/event
Request options:
{ method: 'POST',
  url: 'https://trackcmp.net/event',
  body: 'actid=&key=&event=nodejs_test&eventdata=test1&visit=%7B%22email%22%3A%22test%40test.com%22%7D',
  headers: { 'content-type': 'application/x-www-form-urlencoded' } }
log_event result
{ success: 1, message: 'Event spawned' }

the actid and key in the POST body are empty. Eventhough it says success the event does not show up.

mthommes commented 9 years ago

Sorry about that. Here is a sample that works:

ac.version(2);
ac.track_actid = "myactid";
ac.track_key = "mykey";
ac.track_email = "test@test.com";

ac.credentials_test().then(function (result) {
    // successful request
    if (result.success) {
        var eventdata = {
            event: "nodejs_test",
            eventdata: "test1"
        };

        var log_event = ac.api("tracking/log", eventdata);
        log_event.then(function (result) {
            // successful request
            console.log("log_event result");
            console.log(result);
        }, function (result) {
            // request error
        });
    } else {
        // INVALID ACCOUNT
    }
}, function (result) {
    // request error
});
beda commented 9 years ago

Ok, this works!