Hello,
I am currently experiencing an error on my data results. The error displayed is “Make sure you set the ‘customId’ result in the data results form using the name you used in the code.”
I can confirm that the variable name in the code does match the variable name defined in the data results form, so I’m not sure what is causing this error.
Can you help me to solve this problem?
Thank you in advance for your help.
Here is my code :
const hubspotClient = require(‘@hubspot/api-client’);
exports.main = async (event, callback) => {
const dealId = event.inputFields[‘dealId’];
const toObjectType = “DEAL”;
const toCustomType = “2-112304201”;
const limit = 1;
try {
const apiCustomResponse = await hubspotClient.crm.deals.associationsApi.getAll(dealId, toObjectType, toCustomType,limit);
console.log(JSON.stringify(apiCustomResponse.body, null, 2));
const customArray = apiCustomResponse.body.results ;
const customId = customArray[0].id ;
console.log("The custom object record is: " + customId );
// Récupérer le logement associé à la transaction
const logementId = customArray[0].properties.custom_logement_id.value;
const logementApiResponse = await hubspotClient.crm.objects.basicApi.getById(toCustomType, logementId);
const logement = logementApiResponse.body;
console.log("The logement record is: " + JSON.stringify(logement, null, 2));
// Associer les contacts au logement
const contactsApiResponse = await hubspotClient.crm.contacts.searchApi.doSearch({ query:`custom_logement:${logementId}` });
const contactsArray = contactsApiResponse.body.results ;
const contactsIds = contactsArray.map((contact) => contact.id);
// Associer les propriétaires au logement
const resPrp = await hubspotClient.crm.objects.associationsApi.getPage(logementId, ‘contact’, undefined, 50);
const contactsLot = resPrp.body.results;
for (const association of contactsLot) {
if (association.type == ‘lot_proprietaire’) {
await hubspotClient.crm.contacts.associationsApi.create(association.id, ‘object’, logement.id, ‘lot_proprietaire’, 12);
}
}
callback({
outputFields: {
customId: customId,
dealId: dealId,
contactsIds: contactsIds
}
});
} catch (e) {
//e.message === ‘HTTP request failed’
// ? console.error(JSON.stringify(e.response, null, 2))
// : console. Error(e)
}
}
