UNPKG

get-all-hubspot-companies

Version:

A demo package that allows you to retrieve all your Hubspot companies.

37 lines (28 loc) 1.01 kB
'use strict'; const { axiosFetcher } = require('axios-fetcher'); const count = 100; const getHubspotCompanies = async (token, properties, offset) => { const returnedCompanies = []; let offsetParam; if (typeof offset == 'undefined') offsetParam = null; else offsetParam = `offset=${offset}`; const paramsString = `?count=${count}&${offsetParam}`; const finalUrl = `https://api.hubapi.com/companies/v2/companies/paged${paramsString}&${properties .map((el) => `properties=${el}`) .join('&')}`; const result = await axiosFetcher({ url: finalUrl, method: 'get', headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' }, }); if (result) { result.companies.forEach((contact) => { returnedCompanies.push(contact); }); if (result['has-more']) { return returnedCompanies.concat(await getHubspotCompanies(token, properties, result['offset'])); } return returnedCompanies; } }; module.exports = { getHubspotCompanies };