# Getting an error on integrations

**URL:** <https://community.hubspot.com/t/getting-an-error-on-integrations/77769>\
**Category:** APIs & Integrations\
**Tags:** workflows\
**Created:** [March 22, 2023, 5:56pm UTC](https://community.hubspot.com/t/getting-an-error-on-integrations/77769 "2023-03-22T17:56:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![NHowarth](https://avatars.discourse-cdn.com/v4/letter/n/4bbf92/32.png) [@NHowarth](https://community.hubspot.com/u/NHowarth)\
**Post date:** [March 22, 2023, 5:56pm UTC](https://community.hubspot.com/t/getting-an-error-on-integrations/77769/1 "2023-03-22T17:56:56Z")

</div>

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_0-1679507717477.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/c/d/cd0768a7283c034b0a55d86311c75d3d36d0d9df.png)

---

<div class="post-metadata">

**Author:** ![skimura](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@skimura](https://community.hubspot.com/u/skimura)\
**Post date:** [March 23, 2023, 3:30am UTC](https://community.hubspot.com/t/getting-an-error-on-integrations/77769/2 "2023-03-23T03:30:31Z")

</div>

@NHowarth

Hi.

\> TypeError: Cannot read properties of undefined

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

I think `getById’ returns `SimplePublicObjectWithAssociations`.

> <https://github.com/HubSpot/hubspot-api-nodejs/blob/master/codegen/crm/deals/apis/BasicApi.ts#L419>

`SimplePublicObjectWithAssociations` has property `properties`.

> <https://github.com/HubSpot/hubspot-api-nodejs/blob/master/codegen/crm/deals/models/SimplePublicObjectWithAssociations.ts>

How about this ?

```lia-code-sample
// 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.

---

<div class="post-metadata">

**Author:** ![NHowarth](https://avatars.discourse-cdn.com/v4/letter/n/4bbf92/32.png) [@NHowarth](https://community.hubspot.com/u/NHowarth)\
**Post date:** [March 23, 2023, 7:42am UTC](https://community.hubspot.com/t/getting-an-error-on-integrations/77769/3 "2023-03-23T07:42:47Z")

</div>

Looks like that could be it. Thank you @skimura
