⚙ Operations Hub

PBaxter
投稿者

Custom code for v1 API (Lists)

解決

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件の承認済みベストアンサー
Teun
解決策
名誉エキスパート | Elite Partner
名誉エキスパート | Elite Partner

Custom code for v1 API (Lists)

解決

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.


元の投稿で解決策を見る

2件の返信
a_funs
投稿者

Custom code for v1 API (Lists)

解決

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 いいね!
Teun
解決策
名誉エキスパート | Elite Partner
名誉エキスパート | Elite Partner

Custom code for v1 API (Lists)

解決

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.