APIs & Integrations

albertomedina
Participant

Companies API isn't returning all the companies

SOLVE
Hello,  I need to sync the local database with some info from HubSpot companies. My Node.js code looks something like this:
 
    const returnedCompanies = [];
    const API_KEY = "MY_API_KEY";
    const count = 5;

 

    async function getHubspotCompanies(offset) {

 

        if (typeof offset == 'undefined') {
            offsetParam = null;
        } else { offsetParam = `offset=${offset}`; }
        const hapikeyParam = `hapikey=${API_KEY}`
        const paramsString = `?count=${count}&${hapikeyParam}&${offsetParam}`;
        const finalUrl = `https://api.hubapi.com/companies/v2/companies/paged${paramsString}&properties=name&properties=producto_adquirido`

 

        try {
            const response = await axios.get(finalUrl)
            response.data.companies.forEach(company => {
                returnedCompanies.push(company);
            });

 

            if (response.data['has-more']) { await getHubspotCompanies(response.data['offset']) }
        } catch (error) { console.log('error'error) }
    }
 
It should be returning 2107 companies, but its only returning 141. Is there any problem with my code, or is there some sort of filter from our companies list to what the api returns?
Thank You!
0 Upvotes
1 Accepted solution
quentin_lamamy
Solution
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

Companies API isn't returning all the companies

SOLVE

Hi @albertomedina ,

Thanks @dennisedson for the ping

 

You have two choice :

--> Keep going with your own custom code, but use promise with promise all handler, and the last api endpoint ( Here is the doc )

--> Use the official node SDK with this code :

 

 

const allCompanies = await hubspotClient.crm.companies.getAll()

 

 

 


View solution in original post

4 Replies 4
quentin_lamamy
Solution
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

Companies API isn't returning all the companies

SOLVE

Hi @albertomedina ,

Thanks @dennisedson for the ping

 

You have two choice :

--> Keep going with your own custom code, but use promise with promise all handler, and the last api endpoint ( Here is the doc )

--> Use the official node SDK with this code :

 

 

const allCompanies = await hubspotClient.crm.companies.getAll()

 

 

 


albertomedina
Participant

Companies API isn't returning all the companies

SOLVE

That solved the problem! I ended up using the node SDK option, less of a headache. Thank you!!

dennisedson
HubSpot Product Team
HubSpot Product Team

Companies API isn't returning all the companies

SOLVE

Hey @albertomedina 

@quentin_lamamy is a pro with the CRM APIs!  Maybe he can lend a hand!

albertomedina
Participant

Companies API isn't returning all the companies

SOLVE

thank you!! @quentin_lamamy , i would really appreciate a hand here! 

0 Upvotes