Skip to content
This repository was archived by the owner on Jun 10, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions fixtures/123-abc-456.mktorest.com-443/associate-lead
Original file line number Diff line number Diff line change
@@ -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}
13 changes: 13 additions & 0 deletions fixtures/123-abc-456.mktorest.com-443/find-lead-by-email
Original file line number Diff line number Diff line change
@@ -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}
10 changes: 9 additions & 1 deletion lib/api/lead.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions test/leads.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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);
});
});
});