How to get post code (ZIP) from List object?

I was wondering, is there a way to to get the post code (ZIP) from a list object, if it is even possible? Right now I have the following code that pulls a list object from the HubSpot API, but the post code/ZIP does not return in the output

const express = require('express');
const axios = require('axios');

const app = express();

const hubspot = require('@hubspot/api-client');

const private_app_token = /*my token */
const hubspotClient = new hubspot.Client({"accessToken":private_app_token});

app.get('/contacts/v1/lists/2677/contacts/all', async (req, res) => {

 try {
 const listData = await axios({
 method: 'get',
 url: `https://api.hubapi.com/contacts/v1/lists/2677/contacts/all`,
 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'));

Could you please help me out here? How would I get the post code/ZIP from the list object, if it even exists?

Hey, @ChrisSosa1337 :waving_hand: Thanks for your question! Have you tried using the Get contacts in a list endpoint? This endpoint allows us to add query params such as `property`.

The Get a list by ID endpoint doesn’t offer additional query params.

Here’s a quick example:

  • Gave zip codes to five test contacts

  • I created a List in my portal – last name = Belcher And portal code (zip) is known

  • Used the endpoint – Get contacts in a list

  • Added the additional query params to my request
    https://api.hubapi.com/contacts/v1/lists/50/contacts/all/?property=zip&property=firstname&property=lastname​

  • The contacts and the additional properties are returned in the response

    {
     "contacts": [
     {
     "vid": 801,
     "canonical-vid": 801,
     "merged-vids": [],
     "portal-id": 22245342,
     "is-contact": true,
     "properties": {
     "zip": {
     "value": "87106"
     },
     "firstname": {
     "value": "Louise"
     },
     "lastmodifieddate": {
     "value": "1702058170130"
     },
     "lastname": {
     "value": "Belcher"
     }
     },
     "form-submissions": [],
     "identity-profiles": [
     {
     "vid": 801,
     "saved-at-timestamp": 1667511751622,
     "deleted-changed-timestamp": 0,
     "identities": [
     {
     "type": "EMAIL",
     "value": "louise@bobsburgers.com",
     "timestamp": 1667511751520,
     "is-primary": true
     },
     {
     "type": "LEAD_GUID",
     "value": "29428db3-e768-4f01-ae49-7e23280db908",
     "timestamp": 1667511751618
     }
     ]
     }
     ],
     "merge-audits": [],
     "addedAt": 1702058221138
     },
     {
     "vid": 851,
     "canonical-vid": 851,
     "merged-vids": [],
     "portal-id": 22245342,
     "is-contact": true,
     "properties": {
     "zip": {
     "value": "87106"
     },
     "firstname": {
     "value": "Linda"
     },
     "lastmodifieddate": {
     "value": "1702058170130"
     },
     "lastname": {
     "value": "Belcher"
     }
     },
     "form-submissions": [],
     "identity-profiles": [
     {
     "vid": 851,
     "saved-at-timestamp": 1667511751624,
     "deleted-changed-timestamp": 0,
     "identities": [
     {
     "type": "EMAIL",
     "value": "linda@bobsburgers.com",
     "timestamp": 1667511751560,
     "is-primary": true
     },
     {
     "type": "LEAD_GUID",
     "value": "bd0d9401-ba87-4f6b-93d5-3b7f0205b032",
     "timestamp": 1667511751619
     }
     ]
     }
     ],
     "merge-audits": [],
     "addedAt": 1702058221106
     },
     {
     "vid": 901,
     "canonical-vid": 901,
     "merged-vids": [],
     "portal-id": 22245342,
     "is-contact": true,
     "properties": {
     "zip": {
     "value": "87106"
     },
     "firstname": {
     "value": "Bob"
     },
     "lastmodifieddate": {
     "value": "1702058170130"
     },
     "lastname": {
     "value": "Belcher"
     }
     },
     "form-submissions": [],
     "identity-profiles": [
     {
     "vid": 901,
     "saved-at-timestamp": 1683133205786,
     "deleted-changed-timestamp": 0,
     "identities": [
     {
     "type": "EMAIL",
     "value": "bob@bobsburgers.com",
     "timestamp": 1667511751550,
     "is-primary": true
     },
     {
     "type": "LEAD_GUID",
     "value": "13ff422f-5c71-47e0-8b29-62247b51233d",
     "timestamp": 1667511751626
     },
     {
     "type": "EMAIL",
     "value": "bob2@bobsburgers.com",
     "timestamp": 1683133205772,
     "is-secondary": true
     }
     ]
     }
     ],
     "merge-audits": [],
     "addedAt": 1702058221087
     },
     {
     "vid": 951,
     "canonical-vid": 951,
     "merged-vids": [],
     "portal-id": 22245342,
     "is-contact": true,
     "properties": {
     "zip": {
     "value": "87106"
     },
     "firstname": {
     "value": "Gene"
     },
     "lastmodifieddate": {
     "value": "1702058170130"
     },
     "lastname": {
     "value": "Belcher"
     }
     },
     "form-submissions": [],
     "identity-profiles": [
     {
     "vid": 951,
     "saved-at-timestamp": 1667511751639,
     "deleted-changed-timestamp": 0,
     "identities": [
     {
     "type": "EMAIL",
     "value": "gene@bobsburgers.com",
     "timestamp": 1667511751519,
     "is-primary": true
     },
     {
     "type": "LEAD_GUID",
     "value": "4a114578-68f3-482f-86e8-67b3a99fd2b1",
     "timestamp": 1667511751629
     }
     ]
     }
     ],
     "merge-audits": [],
     "addedAt": 1702058221113
     },
     {
     "vid": 1001,
     "canonical-vid": 1001,
     "merged-vids": [],
     "portal-id": 22245342,
     "is-contact": true,
     "properties": {
     "zip": {
     "value": "87106"
     },
     "firstname": {
     "value": "Tina"
     },
     "lastmodifieddate": {
     "value": "1702058170130"
     },
     "lastname": {
     "value": "Belcher"
     }
     },
     "form-submissions": [],
     "identity-profiles": [
     {
     "vid": 1001,
     "saved-at-timestamp": 1667511751648,
     "deleted-changed-timestamp": 0,
     "identities": [
     {
     "type": "EMAIL",
     "value": "tina@bobsburgers.com",
     "timestamp": 1667511751614,
     "is-primary": true
     },
     {
     "type": "LEAD_GUID",
     "value": "781eb0f3-bb93-4e99-8669-5f635e9e1b0f",
     "timestamp": 1667511751643
     }
     ]
     }
     ],
     "merge-audits": [],
     "addedAt": 1702058220834
     }
     ],
     "has-more": false,
     "vid-offset": 1001
    }​
    

I hope this helps get you moving in the right direction.

Have fun building! — Jaycee

You are a lifesaver! Thanks!