Hubspot Timeline event API Node.JS "TypeError: Cannot read properties of undefined (reading 'eventsA

I’m trying to use the Hubspot Timeline event API to “create a single event” but I keep getting the error:

“TypeError: Cannot read properties of undefined (reading ‘eventsApi’)”.

I’m using the code from here:

With a working access token.

It works when I run it from within the API documentation page but I get the error when I try to run it from my own server(I’m using an actual access Token when I’m running it).

I’m thinking that it has something to do with the: @hubspot/api-client but I can’t figure out why it doesn’t work (it is installed: @hubspot/api-client": “^6.0.1-beta3” and I have tried older versions as well)

async function reportGenerated (){

const hubspot = require('@hubspot/api-client');

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

const tokens = {
 "report-generated": "",
 "yay1": "456",
 "yay2": "2"
};
const extraData = {
 "questions": [
 {
 "question": "Who's a good girl?",
 "answer": "Bark!"
 },
 {
 "question": "Do you wanna go on a walk?",
 "answer": "Woof!"
 }
 ]
};
const timelineIFrame = {
 "linkLabel": "View Art3mis",
 "headerLabel": "Art3mis dog",
 "url": "https://my.petspot.com/pets/Art3mis",
 "width": 600,
 "height": 400
};
const TimelineEvent = { eventTemplateId: "1123354", email: "test@gmail.com", tokens, extraData, timelineIFrame };

try {
 const apiResponse = await hubspotClient.crm.timeline.events.eventsApi.create(TimelineEvent);
 console.log(JSON.stringify(apiResponse.body, null, 2));
} catch (e) {
 e.message === 'HTTP request failed'
 ? console.error(JSON.stringify(e.response, null, 2))
 : console.error(e)
}

}

reportGenerated ();

I figured it out. The path in the documentation is wrong.

Instead of:

hubspotClient.crm.timeline.events.eventsApi.create(TimelineEvent);

it should be

hubspotClient.crm.timeline.eventsApi.create(TimelineEvent);

So “events” need to be removed