Custom workflow code, Node.js ERROR: hubspotClient.crm.contacts.batchApi.upsert is not a function

G’day!

I’m working on a custom workflow step that upserts a list of contacts from a pre-combined string of emails (there are other properties that will be included, but I’m trying to narrow down the upsert issue).

I’ve been able to fetch and update contacts individually, but batch upserting is giving me issues.

I’m following from this example: Accounts Dashboard | HubSpot

According to these docs, it does exist as a method:
https://github.hubspot.com/hubspot-api-nodejs/classes/crm_contacts.BatchApi.html#upsert

I’ve tried not JSON-stringifying the inputs, including and excluding additional contact properties, renaming the apiResponse variable, no luck.

const hubspot = require('@hubspot/api-client');const hubspotClient = new hubspot.Client({"accessToken": process.env.contacts});exports.main = async (event, callback) => {const emails = event.inputFields['email'].split(";"); // email field example: "new1@email.com;new2@email.com"// build update arrayvar batchInputs = [];for (let i = 0; i < emails.length; i++) {let newContact = {"idProperty":"email","id":emails[i], "properties":{ }};batchInputs.push(newContact);}console.log(JSON.stringify(batchInputs)); // prints as [{"idProperty":"email","id":"new1@email.com"},{"idProperty":"email","id":"new2@email.com"}]const upsertInputs = JSON.stringify(batchInputs);const BatchInputSimplePublicObjectBatchInputUpsert = {inputs: upsertInputs};try {const apiResponse = await hubspotClient.crm.contacts.batchApi.upsert(BatchInputSimplePublicObjectBatchInputUpsert);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)}callback({outputFields: {}});}

Hi katiesutcliffe ,

In hubspot there is an inbuilt option of trigger which sends the contacts details as and when its entered, and good part is we can also configure what we need exactly without unnecessary details flowing.
you can check out this video which summarises this using webhook connections.
https://youtu.be/nUpS9zjnL1s?si=mbWZLII_e5GSpxNx
you can visit the below website for more information on this platform.
Bizdata Inc.