I have a bog standard nodejs and express app. I then have a 3rd party API call (https://github.com/agilecrm/nodejs) that has a set function to collect the data I require. Normally, with an DB call, I am fine, where I call the data return it via res.json(data) and and its available client side in the public folder from express, but I seem to really be struggling with the format of the 3rd party function to get the data to return so I can collect it client side.
Here is an example of the api call:
var AgileCRMManager = require("./agilecrm.js");
var obj = new AgileCRMManager("DOMAIN", "KEY", "EMAIL");
var success = function (data) {
console.log(data);
};
var error = function (data) {
console.log(data);
};
obj.contactAPI.getContactsByTagFilter('tester tag',success, error);
This works fine to console the data, but I need to get it client side so I can use it in the front end, and the only method I know is via routing, how would I achieve this, or is there a better method? Its the fact where the data runs via the 2nd element in the function, that I can't get in my response in the various methods I have tried.
app.get('/get_contacts_by_tag', function (req, res) {
obj.contactAPI.getContactsByTagFilter('Confirmed', success, error);
var success = function (data) {
res.json(data);
};
});
Any help would be greatly appreciated.
You didn't define the error callback and also you assign the success callback after the api call.
app.get('/get_contacts_by_tag', function (req, res) {
var success = function (data) {
res.json(data);
};
var error = function (data) {
res.status(500).json(data);
};
obj.contactAPI.getContactsByTagFilter('Confirmed', success, error);
});