HubSpot List Objects - Unable to retrieve ZIP code (Node.js)

22 Views Asked by At

I am having trouble retrieving ZIP codes using HubSpot List objects. I have the following code:

app.get('/contacts/v1/lists/2677/contacts/all?property=zip', async (req, res) => {
    
    try {
      const listData = await axios({
        method: 'get',
        url: `https://api.hubapi.com/contacts/v1/lists/2677/contacts/all?property=zip'`,
        headers: {
          'Authorization': `Bearer ${private_app_token}`,
          'Content-Type': 'application/json'
        }
      }).then(async (response) => {
        const apiResponse = response?.data?.contacts;
      //  let result = apiResponse.map(({properties}) => properties);
        console.log(JSON.stringify(apiResponse));
        return apiResponse;
      }).catch((error) => {
        console.log(`Error while getting list data: ${error.response.data.message}`)
        return null
      })
    } catch (e) {
      e.message === 'HTTP request failed'
        ? console.error(JSON.stringify(e.response, null, 2))
        : console.error(e)
    }
});

function getValueByKey(object, row) {
  return Object.values(object).find(x => object[x] === row.key);
}

app.listen(3000, () => console.log('Listening on http://localhost:3000'));

However, when attempting to run this code, I get an error in my browser and no output in the console. My goal is to try to get the ZIP codes from multiple contacts from a HubSpot list object. There seems to be very little information on the web on how to do this, and none of the solutions seem to work. Could you please help me out? Thank you.

0

There are 0 best solutions below