Getting an error on integrations

I am new the the HubSpot custom code api in their workflows and I keep getting errors when I try testing my code. ANY code, so I am trying to build a generic plug and play sample from the web to see if it is something stupid I am doing but I’m still getting it.

The error Im getting is:

2023-03-22T17:30:09.266Z INFO ******* got this far 2023-03-22T17:30:09.267Z ERROR TypeError: Cannot read properties of undefined (reading ‘properties’) at /var/task/file.js:21:36 at processTicksAndRejections (node:internal/process/task_queues:96:5)

and I can see where it is getting to as I have put in a console.log check message and it looks as though it is failing on the properties and I can’t figure out why. the following is my code:

// The following snippet applies to the Deal object, but can be modified to calculate a property on any Object
// This snippet requires 3 custom properties created in HubSpot:
// “Start Date” (date) / “End Date” (date) / “Duration” (number)

const hubspot = require(‘@hubspot/api-client’);
exports.main = (event, callback) =\> {

// Set up the HubSpot API client
const hubspotClient = new hubspot.Client({
accessToken: process.env.secretName
});

// Use the client to pull information relating to the currently enrolled deal
hubspotClient.crm.deals.basicApi.getById(event.object.objectId, \[“start_date”,“duration”,\])
.then(results =\> {

// Store properties in variables

console.log(“******* got this far”);
let startDate = results.body.properties.start_date;
let duration = results.body.properties.duration;

// Calculate the end date from the variables input
let d = new Date(startDate)
let i = parseInt(duration)
let r= new Date(d.setDate(d.getDate()+i))
r= r.getTime()

callback({
// Store the calculated date in a workflow output - don’t forget to copy that value to your “End date” property
outputFields: {
end_date: r
}
});
})
.catch(err => {
console.error(err);
});
}

my other properties are

@NHowarth

Hi.

> TypeError: Cannot read properties of undefined

I think the place where `properties` is used is suspicious.

I think `getById’ returns `SimplePublicObjectWithAssociations`.

`SimplePublicObjectWithAssociations` has property `properties`.

How about this ?

// Use the client to pull information relating to the currently enrolled deal
hubspotClient.crm.deals.basicApi.getById(event.object.objectId, ["start_date","duration",])
 .then(results => {
 // Store properties in variables
 console.log("******* got this far");

 //let startDate = results.body.properties.start_date;
 //let duration = results.body.properties.duration;
 let startDate = results.properties["start_date"];
 let duration = results.properties["duration"];

 ...

});

Thanks.

Looks like that could be it. Thank you @skimura