Unable to create association from deals to contact!

Hi Team,

I am getting this issue while trying to create association with deal to cintact through api.Below is my code.

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

const hubspotClient = new hubspot.Client({“apiKey”:“api key here”});

const BatchInputPublicAssociation = { inputs: [{“from”:{“id”:“deal_id here”},“to”:{“id”:“contact-id here”},“type”:“deal_to_contact”}] };
const fromObjectType = “Deals”;
const toObjectType = “Contacts”;

try {
const apiResponse = await hubspotClient.crm.associations.batchApi.create(fromObjectType, toObjectType, BatchInputPublicAssociation);
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)
}

Error:

{
[0] “statusCode”: 500,
[0] “body”: {
[0] “status”: “error”,
[0] “message”: “internal error”,
[0] “correlationId”: “7f3142a4-9ff8-42c8-8804-27b73c506114”
[0] },

I even tried this Accounts Dashboard | HubSpot endpoint and this one PUT…/crm/v3/objects/deals/{dealId}/associations/{toObjectType}/{toObjectId}/{associationType}

as well but with same error.

@SBhujel , Did you get this resolved?

I reformatted a bit like this (dummy ids for deal and contact)

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

const hubspotClient = new hubspot.Client({"apiKey":"YOUR_HUBSPOT_API_KEY"});

const dealId = "333211";
const toObjectType = "contacts";
const toObjectId = "1111";
const associationType = "deal_to_contact";

try {
 const apiResponse = await hubspotClient.crm.deals.associationsApi.create(dealId, toObjectType, toObjectId, associationType);
 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)
}

Thanks Dennis, yes it worked for me now!

What exactly did you do to resolve the issue, I’m getting same error when trying this through Postman.

Amazing, was exactly what I need :nerd_face: