APIs & Integrations

CMetaliya
Member

Batch Update API Is not working even when passed right object

SOLVE

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.

 

Capture-1.PNG

Here's the response that I got by calling this method.

Capture-1.PNG

Both contact IDs are present and I've obtained those contact IDs from hubspot search API only.

 

Any help would be highly appreciated. 

0 Upvotes
1 Accepted solution
Teun
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Batch Update API Is not working even when passed right object

SOLVE

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)
}


Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


View solution in original post

3 Replies 3
CMetaliya
Member

Batch Update API Is not working even when passed right object

SOLVE

I didn't get you buddy. TEST means?

0 Upvotes
Teun
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Batch Update API Is not working even when passed right object

SOLVE

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



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


Teun
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Batch Update API Is not working even when passed right object

SOLVE

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)
}


Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.