Skip to content

Commit

Permalink
Merge pull request #287 from friggframework/feature/fri-148-improve-l…
Browse files Browse the repository at this point in the history
…istcontacts-for-hubspot-api

Improve listcontacts for hubspot api
  • Loading branch information
leofmds authored Mar 26, 2024
2 parents b4e395b + a91a7e4 commit 4bc6b83
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions api-module-library/hubspot/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,8 @@ class Api extends OAuth2Requester {
}

async getCompanyById(compId) {
const props = await this.listProperties('company');
let propsString = '';
for (let i = 0; i < props.results.length; i++) {
propsString += `${props.results[i].name},`;
}
propsString = propsString.slice(0, propsString.length - 1);
const propsString = await this._propertiesList('company');

const options = {
url: this.baseUrl + this.URLs.companyById(compId),
query: {
Expand Down Expand Up @@ -187,9 +183,22 @@ class Api extends OAuth2Requester {
return this._post(options);
}

async listContacts() {
async listContacts(params) {
const limit = get(params, 'limit', 100);
const after = get(params, 'after', null);

let properties = get(params, 'properties', null);
if (!properties) {
properties = await this._propertiesList('contact');
}

const options = {
url: this.baseUrl + this.URLs.contacts,
query: {
limit,
after,
properties,
}
};

return this._get(options);
Expand All @@ -204,12 +213,8 @@ class Api extends OAuth2Requester {
}

async getContactById(contactId) {
const props = await this.listProperties('contact');
let propsString = '';
for (let i = 0; i < props.results.length; i++) {
propsString += `${props.results[i].name},`;
}
propsString = propsString.slice(0, propsString.length - 1);
const propsString = await this._propertiesList('contact');

const options = {
url: this.baseUrl + this.URLs.contactById(contactId),
query: {
Expand Down Expand Up @@ -282,12 +287,8 @@ class Api extends OAuth2Requester {
}

async getDealById(dealId) {
const props = await this.listProperties('deal');
let propsString = '';
for (let i = 0; i < props.results.length; i++) {
propsString += `${props.results[i].name},`;
}
propsString = propsString.slice(0, propsString.length - 1);
const propsString = await this._propertiesList('deal');

const options = {
url: this.baseUrl + this.URLs.dealById(dealId),
query: {
Expand All @@ -310,12 +311,8 @@ class Api extends OAuth2Requester {
// pageObj can look something like this:
// { limit: 10, after: 10 }
async listDeals(pageObj) {
const props = await this.listProperties('deal');
let propsString = '';
for (let i = 0; i < props.results.length; i++) {
propsString += `${props.results[i].name},`;
}
propsString = propsString.slice(0, propsString.length - 1);
const propsString = await this._propertiesList('deal');

const options = {
url: this.baseUrl + this.URLs.deals,
query: {
Expand Down Expand Up @@ -722,12 +719,6 @@ class Api extends OAuth2Requester {
// ************************** Owners **********************************

async getOwnerById(ownerId) {
// const props = await this.listProperties('owner');
// let propsString = '';
// for (let i = 0; i < props.results.length; i++) {
// propsString += `${props.results[i].name},`;
// }
// propsString = propsString.slice(0, propsString.length - 1);
const options = {
url: this.baseUrl + this.URLs.getOwnerById(ownerId),
};
Expand Down Expand Up @@ -1015,6 +1006,16 @@ class Api extends OAuth2Requester {
const { results } = res;
return results;
}

async _propertiesList(objType) {
const props = await this.listProperties(objType);
let propsString = '';
for (let i = 0; i < props.results.length; i++) {
propsString += `${props.results[i].name},`;
}
propsString = propsString.slice(0, propsString.length - 1);
return propsString;
}
}

module.exports = { Api };

0 comments on commit 4bc6b83

Please sign in to comment.