I’m working with the HubSpot timeline events API in Node.js and getting a frustrating error when trying to create timeline events. The error message says “TypeError: Cannot read properties of undefined (reading ‘eventsApi’)”.
The weird thing is that the same code works fine when I test it directly on the HubSpot developer documentation page, but fails when I run it on my local server. I’m using a valid access token and have the @hubspot/api-client package installed (version 6.0.1-beta3). I also tried downgrading to older versions but still get the same issue.
Anyone know what might be causing this eventsApi property to be undefined? Could it be a version compatibility issue or am I missing something in the setup?
Looking at your code, there’s another angle to consider beyond just the API path issue. I ran into something similar when working on a customer portal integration and discovered that the timeline events module isn’t always fully initialized depending on how you instantiate the client. Try adding a small delay or check before making the API call to ensure all modules are properly loaded. In my case, wrapping the client initialization in a separate function and adding proper error handling for the module availability fixed intermittent undefined errors. The beta version you’re using might have race conditions during module initialization that don’t occur in the HubSpot documentation environment. Also worth noting that some timeline event operations require the client to be initialized with specific configuration options that aren’t always obvious from the basic examples.
Been wrestling with HubSpot API integrations for a while now and this error usually stems from version mismatches between the documentation and the actual package implementation. Since you mentioned using version 6.0.1-beta3, that’s likely your culprit right there. Beta versions often have unstable API structures that don’t match the official docs. I’d recommend rolling back to the latest stable release instead of the beta version. When I had similar issues, switching to version 5.0.0 resolved the undefined property errors immediately. The beta releases tend to have breaking changes that aren’t fully documented yet. Also worth checking if your access token has the correct scopes for timeline events specifically, as scope issues can sometimes manifest as undefined property errors rather than clear permission denied messages.
Had similiar headache last week! try destructuring the import differently - const { Client } = require('@hubspot/api-client') instead of importing the whole package. sometimes the constructor isn’t properly exposed when you import the entire module. also double check your node version, hubspot client can be picky about compatibility.
I encountered this exact issue a few months back and it drove me crazy for hours. The problem is with the API path structure in the newer versions of the HubSpot client. The eventsApi property doesn’t exist in that nested structure anymore. Try changing your API call from client.crm.timeline.events.eventsApi.create(eventData) to just client.crm.timeline.events.create(eventData). The API structure was simplified and the eventsApi layer was removed. Also, make sure you’re not mixing up timeline events with the older events API. The timeline events have a different endpoint structure now. I had to update several of my integrations when they changed this in the v6 client library. The documentation examples sometimes lag behind the actual implementation changes.
This issue caught me off guard when I was migrating an old project to the newer HubSpot client. The timeline events API underwent significant structural changes and the nested property access you’re using is outdated. Instead of accessing client.crm.timeline.events.eventsApi.create(), the correct method is client.crm.timeline.events.create(). The events layer in your path is redundant in the current implementation. I spent considerable time debugging this exact error before realizing the API documentation hadn’t been updated to reflect the actual client structure. Your event data structure looks correct, but the access path needs adjustment. Also verify that your HubSpot app has timeline events permissions enabled in the developer console, as this can sometimes throw misleading error messages.