I’m having issues getting Deal Object property values from Hubspot using their API in Node.js. The API call works fine in Postman, showing all the property values I asked for. But when I try the same thing in Node.js, I only get [Object] for the properties instead of the actual values.
Here’s a quick example of what I’m seeing in Node.js:
const fetchDeals = async () => {
const apiKey = 'your-api-key'
const endpoint = `https://api.hubapi.com/deals/v1/deal/paged?hapikey=${apiKey}&properties=dealname,dealstage`
try {
const response = await fetch(endpoint)
const data = await response.json()
console.log(data.deals[0].properties) // Outputs: [Object]
} catch (error) {
console.error('Error fetching deals:', error)
}
}
fetchDeals()
I expected to see the actual dealname and dealstage values, but I’m just getting [Object]. Any ideas on what I’m doing wrong or how to fix this?
I’ve dealt with this exact problem when working with the HubSpot API. The issue isn’t with your API call, but rather how Node.js handles nested objects in console output. What’s happening is that the properties are actually there, but they’re nested one level deeper than you might expect.
Try accessing the specific property values directly, like this:
console.log(data.deals[0].properties.dealname.value);
console.log(data.deals[0].properties.dealstage.value);
This should give you the actual values you’re looking for. Alternatively, if you want to see all properties at once, you could use Object.entries() to iterate over them:
Object.entries(data.deals[0].properties).forEach(([key, value]) => {
console.log(`${key}: ${value.value}`);
});
This approach has always worked for me when dealing with HubSpot’s API responses. Let me know if you need any further clarification!
I’ve encountered similar issues with the HubSpot API. The problem lies in how Node.js handles nested objects in console output. The property values are actually there, just one level deeper than expected.
To access the specific values, try this approach:
console.log(data.deals[0].properties.dealname.value);
console.log(data.deals[0].properties.dealstage.value);
This should display the actual values you’re looking for. Alternatively, for a more comprehensive view, you could use a loop:
for (let prop in data.deals[0].properties) {
console.log(`${prop}: ${data.deals[0].properties[prop].value}`);
}
This method has proven effective in my experience with HubSpot’s API responses. It should solve your issue and provide the data you need.
hey there! i’ve run into this before. the issue is that console.log() doesn’t show nested object properties by default. try using console.log(JSON.stringify(data.deals[0].properties, null, 2)) instead. this will give you a formatted string with all the nested values. hope that helps!