APIs & Integrations

PhilThomas
Participant | Diamond Partner
Participant | Diamond Partner

Creating a custom object and associating it with a contact using Custom Coded Workflows

Hi all.

 

I'm attempting to create a custom object using custom coded workflows. When testing using the documentation "Test Call" feature, it works exactly as expected, creating a new "Test" object record, and associating it with the correct Contact. Below is the example code.

 

const hubspot = require('@hubspot/api-client');

const hubspotClient = new hubspot.Client({"accessToken":"YOUR_ACCESS_TOKEN"});

const properties = {
  "test_name": "Test",
  "amount": 80.59
};
const SimplePublicObjectInputForCreate = { associations: [{"types":[{"associationCategory":"USER_DEFINED","associationTypeId":19}],"to":{"id":"4351"}}], properties };
const objectType = "2-9289205";

try {
  const apiResponse = await hubspotClient.crm.objects.basicApi.create(objectType, SimplePublicObjectInputForCreate);
  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)
}

 

 

However, when copying the code over the record is created but the association isn't made.

 

const properties = { 
  "test_name": `New Project - ${event.inputFields['name']}`,
  "amount": results_array[i].properties.amount
}

const SimplePublicObjectInputForCreate = { associations: [{"types":[{"associationCategory":"USER_DEFINED","associationTypeId":19}],"to":{"id":"4351"}}], properties };

try {
  var createObject = await hubspotClient.crm.objects.basicApi.create("2-9289205", SimplePublicObjectInputForCreate)
}

 

 

As you can see the "Test Call" works, and the code (whilst not identical, is still the same format) doesn't.

Screenshot 2023-11-02 154230.png

 

I suspect this is because the documentation is using "v3" of the HubSpot client, whereas by default HubSpot custom coded workflows use "v8". 

 

Are there any changelogs or documentation available that outline the changes to "crm.objects.basicApi.create" so I can get the association working with v8?

 

EDIT: I refactored my workflow code to use v3. I was hoping that changing the version I was using to be identical to the documentation would solve everything, but unfortunately it's the same issue 😓

 

 

0 Upvotes
1 Reply 1
Jaycee_Lewis
Community Manager
Community Manager

Creating a custom object and associating it with a contact using Custom Coded Workflows

Hey, @PhilThomas 👋 Thanks for making sure to include all your details. I'd like to ask some of our community members to share their insights — hey @Teun @JBeatty, do you have any recent experience you can share with @PhilThomas?

 

Thank you very much! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot