I’m trying to implement batch update functionality in one of my nodeJs applications using Hubspot API and when I call, batch update method of contacts, it returns an empty array and nothing is changed in my hubspot account either.
My request objects is as same as mentioned in the documentation here.
https://legacydocs.hubspot.com/docs/methods/contacts/batch_create_or_update
I’m trying to figure out issue since last two days but didn’t found any solution. Please help.
Here’s the code I’ve implemented so far.
Here’s the response that I got by calling this method.
Both contact IDs are present and I’ve obtained those contact IDs from hubspot search API only.
Any help would be highly appreciated.
I didn’t get you buddy. TEST means?
Teun
May 23, 2022, 12:57pm
3
My replies keep getting deleted once I paste code. Let me try this again.
The NPM package uses the v3 version of the API. So you should use these docs .
Teun
May 23, 2022, 12:59pm
4
Your code should look something like this:
const hubspot = require('@hubspot/api-client');
let updateObj = [
{
id: '1801',
properties: [
{ property: 'firstname', value: 'random' },
{ property: 'lastname', value: 'random' },
{ property: 'email', value: 'example@hubspot.com' },
{ property: 'phone', value: '000-000-0000' },
]
},
{
id: '1851',
properties: [
{ property: 'firstname', value: 'random' },
{ property: 'lastname', value: 'random' },
{ property: 'email', value: 'example3@hubspot.com' },
{ property: 'phone', value: '000-000-0000' },
]
}
]
const inputs = JSON.stringify(updateObj)
const BatchInputSimplePublicObjectBatchInput = { inputs: inputs };
try {
const apiResponse = await hubspotClient.crm.contacts.batchApi.update(BatchInputSimplePublicObjectBatchInput);
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)
}