diff --git a/fixtures/123-abc-456.mktorest.com-443/associate-lead b/fixtures/123-abc-456.mktorest.com-443/associate-lead new file mode 100644 index 0000000..635df56 --- /dev/null +++ b/fixtures/123-abc-456.mktorest.com-443/associate-lead @@ -0,0 +1,14 @@ +POST /rest/v1/leads/578705/associate.json?cookie=id:356-YFG-389%26token:_mch-mydomain.com-dce599ec86f1c3773ce075014267c852 +accept: application/json, text/plain, */* +content-type: application/json +accept-encoding: gzip, compress, deflate, br +body: {} + +HTTP/1.1 200 200 +server: nginx +date: Wed, 04 Dec 2024 17:42:57 GMT +content-type: application/json;charset=UTF-8 +content-length: 59 +connection: close + +{"requestId":"4cda#19392c49414","result":[],"success":true} \ No newline at end of file diff --git a/fixtures/123-abc-456.mktorest.com-443/find-lead-by-email b/fixtures/123-abc-456.mktorest.com-443/find-lead-by-email new file mode 100644 index 0000000..14fa8ed --- /dev/null +++ b/fixtures/123-abc-456.mktorest.com-443/find-lead-by-email @@ -0,0 +1,13 @@ +GET /rest/v1/leads.json?fields=email,lastName&filterType=email&filterValues=foo%40gmail.com +accept: application/json, text/plain, */* +accept-encoding: gzip, compress, deflate, br + +200 HTTP/1.1 +server: nginx +date: Wed, 19 Nov 2014 23:15:13 GMT +content-type: application/json;charset=UTF-8 +content-length: 121 +connection: keep-alive +set-cookie: BIGipServerab-restapi_https=587792650.47873.0000; path=/ + +{"requestId":"179d7#149ca5697d6","result":[{"id":1,"lastName":"test","email":"ak+marketo1@usermind.com"}],"success":true} \ No newline at end of file diff --git a/lib/api/lead.js b/lib/api/lead.js index 7b52439..c08e2ec 100644 --- a/lib/api/lead.js +++ b/lib/api/lead.js @@ -32,7 +32,15 @@ Lead.prototype = { }); options = util.formatOptions(options); - return this._connection.get(path, { query: options }); + let queryString = undefined; + let body = {}; + if (filterType === 'id') { + body = { query: options }; + } else { + queryString = { query: options }; + } + + return this._connection.get(path, body, queryString); }, createOrUpdate: function (input, options) { diff --git a/lib/connection.js b/lib/connection.js index a606a89..0b1b5bd 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -52,7 +52,7 @@ Connection.prototype._request = function (method) { var requestFn = function requestFn(forceOAuth) { return this.getOAuthToken(forceOAuth).then( function (token) { - var [_a, data] = args; + var [_a, data, qs] = args; var nextPageFn = getNextPageFn(this, method, args); @@ -63,6 +63,9 @@ Connection.prototype._request = function (method) { options.url = url; options.method = method; options.data = data; + if (qs?.query) { + options.params = qs.query; + } return new Promise((resolve, reject) => { return axios(options) diff --git a/test/leads.test.js b/test/leads.test.js index 4fff75c..8afb285 100644 --- a/test/leads.test.js +++ b/test/leads.test.js @@ -93,6 +93,21 @@ describe('Leads', function () { done(); }); }); + + it('by email - uses multiple filter values and retrieve a subset of fields', function (done) { + marketo.lead + .find('email', ['foo@gmail.com'], { fields: ['email', 'lastName'] }) + .then(function (resp) { + assert.equal(resp.result.length, 1); + assert.equal(resp.result[0].id, 1); + + var lead = resp.result[0]; + assert.equal(lead.id, 1); + assert(_.has(lead, 'email')); + assert(_.has(lead, 'lastName')); + done(); + }); + }); }); describe('#createOrUpdate', function () { @@ -110,4 +125,16 @@ describe('Leads', function () { .catch(done); }); }); + + describe('#associateLead', function () { + it('finds a lead by id only', function (done) { + marketo.lead + .associateLead(578705, 'id:356-YFG-389&token:_mch-mydomain.com-dce599ec86f1c3773ce075014267c852') + .then(function (response) { + assert.equal(response.result.length, 0); + done(); + }) + .catch(done); + }); + }); });