简体   繁体   中英

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

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: "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" needs to be removed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM