⚙ Operations Hub

PBaxter
Colaborador

Custom code for v1 API (Lists)

resolver

Hi,

 

Does anyone know the format to reference the v1 API from custom code with Node js? I'm trying to use the contact list API.

 

For v3, the API URL to get contact info is something like:
/crm/v3/objects/contacts/2360301

 

And the equivalent js is:
hubspotClient.crm.contacts.basicApi.getById(item.id, .....) (where item.id = 2360301)

 

For v1, an example API URL is to get a list is:
/contactslistseg/v1/lists/1

 

But I can't get the js equivalent to get data on list #1. Feels it should just be using hubSpotClient.contactslistseg.lists... but that
gives an undefined error.

 

Thanks for any ideas! Feels like I've tried every possible combination.

 

Phil

1 Soluciones aceptada
Teun
Solución
Experto reconocido | Partner nivel Elite
Experto reconocido | Partner nivel Elite

Custom code for v1 API (Lists)

resolver

Hi @PBaxter ,

 

I went through the github of the NodeJS API, but I can not discover a .ts file for the lists. The discovery folder is my go to place to check for all the available functions. But lists simply seem to be missing NodeJS API.
If you are familiar with Axios, you should be able to use that instead. Here is an example:

 

const axios = require('axios');

const listData = await axios({
        method: 'get',
        url: `https://api.hubapi.com/contacts/v1/lists/1`,
        headers: {
          'Authorization': `Bearer ${process.env.authtoken}`,
          'Content-Type': 'application/json'
        }
      }).then(async (response) => {
        console.log(response.data)
        return response.data
      }).catch((error) => {
        console.log(`Error while getting list data: ${error.response.data.message}`)
        return null
      })

 



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


Ver la solución en mensaje original publicado

2 Respuestas 2
a_funs
Colaborador

Custom code for v1 API (Lists)

resolver

For the older apis, you can use the apiRequest method via the hubspot js sdk. For instance

 

const response = await hubspotClient.apiRequest({
    method: 'get',
    path: '/contactslistseg/v1/lists/1',
})

 

See documentation https://github.com/HubSpot/hubspot-api-nodejs/tree/master#get-contacts

0 Me gusta
Teun
Solución
Experto reconocido | Partner nivel Elite
Experto reconocido | Partner nivel Elite

Custom code for v1 API (Lists)

resolver

Hi @PBaxter ,

 

I went through the github of the NodeJS API, but I can not discover a .ts file for the lists. The discovery folder is my go to place to check for all the available functions. But lists simply seem to be missing NodeJS API.
If you are familiar with Axios, you should be able to use that instead. Here is an example:

 

const axios = require('axios');

const listData = await axios({
        method: 'get',
        url: `https://api.hubapi.com/contacts/v1/lists/1`,
        headers: {
          'Authorization': `Bearer ${process.env.authtoken}`,
          'Content-Type': 'application/json'
        }
      }).then(async (response) => {
        console.log(response.data)
        return response.data
      }).catch((error) => {
        console.log(`Error while getting list data: ${error.response.data.message}`)
        return null
      })

 



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.