Creating associations in hubspot-api-nodejs new version
Hi everyone! I'm using the nodejs-api for the first time, but I was reading the documentation, and the readme still needed to be updated. This readme (https://github.com/HubSpot/hubspot-api-nodejs#example-create-contact-company-and-associate-created-o...) it's using crm.associations.v4.basicApi.create to create an association, but the current node API has: crm.associations.v4.definitionsApi.create, which has different parameters. Could someone help me create an association with this API version? The idea it's to create in the exact same way from the readme example
Creating associations in hubspot-api-nodejs new version
You can create assocaition while creating the contact object or company object. In v9 of node hubspot/api-client. You need to pass associations parameter while creating an object. An example of creating a note and associate with contact. ```
// Create a new client const client = new hubspot.Client({ apiKey: '<your-api-key>', hubspotUrl: '<your-hubspot-url>', });
// Get the contact and company records const contact = await client.crm.objects.contacts.get({ id: '<contact-id>', });
const company = await client.crm.objects.companies.get({ id: '<company-id>', });
// Create the association const association = await client.crm.associations.v4.definitionsApi.create({ fromObjectType: 'contact', fromObjectId: contact.id, toObjectType: 'company', toObjectId: company.id, }); ```
This code will create an association between the contact and company records. The `fromObjectType` and `fromObjectId` properties specify the contact record, and the `toObjectType` and `toObjectId` properties specify the company record.
Hope this will helps you out. Please mark it as Solution Accepted to help other Community member. Thanks!
The associationRequest object contains the following properties:
fromObjectType: The type of the object you're associating (e.g. contact). fromObjectId: The ID of the record to associate. toObjectType: The type of the object you're associating the record to (e.g. company). toObjectId: The ID of the record to associate to. associationType: The type of association you want to create. The default value is "default".
Creating associations in hubspot-api-nodejs new version
I am not sure what exactly are you trying to do, but if you want to use an HS defined association, just use the crm.associations.v4.basicApi.createDefault(). It receives the 4 first arguments as you sent it, and that's all. The create() allows you to define new custom association types, and label them. The basic association between contact and company already defined by HS (and so, it's considered "unlabeled").