diff --git a/agilecrm/agilecrm.js b/agilecrm/agilecrm.js index f8b3fde..97cb81e 100644 --- a/agilecrm/agilecrm.js +++ b/agilecrm/agilecrm.js @@ -144,6 +144,39 @@ ContactAPI.prototype.getContactByEmail = function getContactByEmail(email, succe }); }; +ContactAPI.prototype.getContactByPhoneNumber = function getContactByPhoneNumber(number, success, failure) { + var options = this.getOptions(); + options.path = '/dev/api/contacts/search/phonenumber/' + number; + + https.get(options, function (resp) { + var body = ""; + resp.on('data', function(data) { + body += data; + }); + resp.on('end', function() { + if (success) { + try { + console.log("Status Code = " + resp.statusCode); + console.log("reply is ", body); + var contacts = JSON.parse(body); + success(contacts, resp.statusCode); + } catch (ex) { + success([], resp.statusCode); + } + } + }); + resp.on('error', function(e) { + if (failure) { + failure(e); + } + }); + }).on("error", function(e) { + if (failure) { + failure(e); + } + }); +}; + ContactAPI.prototype.add = function add(contact, success, failure) { var options = this.getOptions(); options.path = '/dev/api/contacts';