# Basic custom code for accessing timeline

**URL:** <https://community.hubspot.com/t/basic-custom-code-for-accessing-timeline/79052>\
**Category:** APIs & Integrations\
**Created:** [April 11, 2023, 10:51am UTC](https://community.hubspot.com/t/basic-custom-code-for-accessing-timeline/79052 "2023-04-11T10:51:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PBaxter](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pbaxter/32/86357_2.png) [@PBaxter](https://community.hubspot.com/u/PBaxter)\
**Post date:** [April 11, 2023, 10:51am UTC](https://community.hubspot.com/t/basic-custom-code-for-accessing-timeline/79052/1 "2023-04-11T10:51:46Z")

</div>

Hi,

I’ve got a company custom code workflow which does a simple summary of company properties and associated objects, and pushes them into an at-a-glance ‘tear sheet’ property.

It’s basically using the company ID to get associations to contacts, deals, etc. and then filtering out highlights.

All works fine until I get to trying to find the last emails on a company. I’m trying to access the ‘get email by ID’ endpoint, as documented here:

> **[Accounts Dashboard | HubSpot](https://app.hubspot.com/myaccounts?next=developerdocs&redirect=%2Fapi-reference%2Fcrm-emails-v3%2Fguide)**

With this:

//First, make a call to get company associations to emails:

hubspotClient.crm.companies.associationsApi.getAll(event.object.objectId, ‘emails’).then((results) =\> {  
let emailPromises = results.body.results.map(item =\> {  
return hubspotClient.crm.objects.emails.basicApi.getById(item.id, [‘hs\_timestamp’,‘hs\_email\_subject’]).then(results =\> {  
return results.body  
})  
})

which doesn’t like the getById definition:

`ERROR	TypeError: Cannot read properties of undefined (reading 'getById')`

As far as I can see, I’m using the same definition as in the API docs, which states: _const apiResponse = await hubspotClient.crm.objects.emails.basicApi.getById(emailId, properties, …)_

Any ideas gratefully received!

Phil

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [April 12, 2023, 5:58pm UTC](https://community.hubspot.com/t/basic-custom-code-for-accessing-timeline/79052/2 "2023-04-12T17:58:25Z")

</div>

Hey, @PBaxter 👋 Thanks for reaching out. Let’s invite some of our community members to the conversation — @albertsg @miljkovicmisa, do you have any troubleshooting tips you can share with @PBaxter?

Looking at the documentation example they linked to, I’m not spotting any quick red flags with the provided code snippet:

From the documentation:

```lia-code-sample
const hubspot = require('@hubspot/api-client');

const hubspotClient = new hubspot.Client({"accessToken":"YOUR_ACCESS_TOKEN"});

const emailId = "emailId";
const properties = undefined;
const propertiesWithHistory = undefined;
const associations = undefined;
const archived = false;
const idProperty = undefined;

try {
 const apiResponse = await hubspotClient.crm.objects.emails.basicApi.getById(emailId, properties, propertiesWithHistory, associations, archived, idProperty);
 console.log(JSON.stringify(apiResponse, null, 2));
} catch (e) {
 e.message === 'HTTP request failed'
 ? console.error(JSON.stringify(e.response, null, 2))
 : console.error(e)
}

```

Original snippet:

```lia-code-sample
//First, make a call to get company associations to emails:

hubspotClient.crm.companies.associationsApi.getAll(event.object.objectId, 'emails').then((results) => {

let emailPromises = results.body.results.map(item => {
return hubspotClient.crm.objects.emails.basicApi.getById(item.id, ['hs_timestamp','hs_email_subject']).then(results => {
return results.body
})
})

```

Thanks for taking a look! — Jaycee
