node.js - Passing data from vendor API to client side for processing -


i have bog standard nodejs , express app. have 3rd party api call (https://github.com/agilecrm/nodejs) has set function collect data require. normally, db call, fine, call data return via res.json(data) , and available client side in public folder express, seem struggling format of 3rd party function data return can collect client side.

here example of 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 console data, need client side can use in front end, , method know via routing, how achieve this, or there better method? fact data runs via 2nd element in function, can't in response in various methods 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 appreciated.

you didn't define error callback , assign success callback after 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); }); 

Comments