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: https://developers.hubspot.com/docs/api/crm/timeline With a working access token.
It works when I run it from within their 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 is 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: "[email protected]", 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:
it should be
So "events" needs to be removed