I need to create a Deal with some properties and some associations. I am doing it as follows but it doesn’t work:
It works fine when not providing the associations property, so I assume the associations poroperty is incorrectly structured, but also I don’t find the proper structure anywhere.
const deal = { properties: { dealname: dealname, estimated_shipping_date: new Date(estimatedshippingdate).getTime(), product_division: productDivision, }, associations: { associatedVids: [contacthubspotid], associatedCompanyIds: [hubspotcompanyid], },};
hubspotClient.crm.deals.basicApi.create(deal).then{ ... }
Also, I tried defining the deal object as follows, based on the documentation:
const deal = { properties: { dealname: dealname, estimated_shipping_date: new Date(estimatedshippingdate).getTime(), product_division: productDivision, }, associations: [ { to: contacthubspotid, types: [ { associationCategory: "HUBSPOT_DEFINED", associationTypeId: 3 // 'deal_to_contact' } ] }, { to: hubspotcompanyid, types: [ { associationCategory: "HUBSPOT_DEFINED", associationTypeId: 341 // 'deal_to_company' } ] } ]};
Does not work.
I also tried:
await hubspotClient.crm.deals.basicApi.create(deal) .then(async response => { // Extract the deal ID from the response const dealId = response.body.id; context.info(Deal created in HubSpot with ID: ${dealId}); await hubspotClient.crm.associations.basicApi.create('deals', dealId, 'contact', contacthubspotid).then(response => { context.info(Deal associated with contact in HubSpot: ${response.body}); }); await hubspotClient.crm.associations.basicApi.create('deals', dealId, 'company', hubspotcompanyid).then(response => { context.info(Deal associated with company in HubSpot: ${response.body}); });
But it does not create the association. It creates the deal though.