I’m working with HubSpot workflows and trying to use their custom code feature. Every time I run my script I get an error about properties being undefined. Here’s what happens:
const hubspot = require('@hubspot/api-client');
exports.main = (event, callback) => {
const client = new hubspot.Client({
accessToken: process.env.TOKEN_SECRET
});
client.crm.deals.basicApi.getById(event.object.objectId, ["created_date", "amount"])
.then(response => {
console.log("API call successful");
let createdDate = response.body.properties.created_date;
let dealAmount = response.body.properties.amount;
let processedDate = new Date(createdDate);
let finalAmount = parseInt(dealAmount) * 1.1;
callback({
outputFields: {
processed_date: processedDate.getTime(),
final_amount: finalAmount
}
});
})
.catch(error => {
console.error(error);
});
};
The error message shows: TypeError: Cannot read properties of undefined (reading 'properties') and it points to the line where I try to access response.body.properties. The console log shows the API call works but then it fails right after. What could be causing the response structure to be different than expected?