Hey all, I am making a custom code to get all the line items associated with a deal in one string and then add them to a sheet in another step and I am a bit stuck in it.
this is the error I’m getting:
2025-01-21T09:38:08.256Z ERROR Error in workflow execution: hubspotClient.crm.associations.getAll is not a function
Memory: 79/128 MB
Runtime: 753.15 ms
and here is the code:
const hubspot = require(‘@hubspot/api-client’);
exports.main = async (event, callback) => {
const hubspotClient = new hubspot.Client({ accessToken: process.env.HSAPISara });
try {
// Retrieve the deal ID from the workflow event
const dealId = event.object.objectId;
// Get associated line items
const associationsResponse = await hubspotClient.crm.associations.getAll(“deal”, dealId, “line_item”);
if (!associationsResponse || !associationsResponse.results) {
throw new Error(“No associated line items found.”);
}
const lineItemIds = associationsResponse.results.map(association => association.id);
// Fetch line item details
const lineItemPromises = lineItemIds.map(async lineItemId => {
const lineItemResponse = await hubspotClient.crm.lineItems.basicApi.getById(lineItemId, [“name”]);
if (!lineItemResponse || !lineItemResponse.body || !lineItemResponse.body.properties) {
throw new Error(`Line item with ID ${lineItemId} is missing properties.`);
}
return lineItemResponse.body.properties.name;
});
const lineItemNames = await Promise.all(lineItemPromises);
// Return the line item names
callback(null, {
outputFields: {
line_items: lineItemNames.join(", ")
}
});
} catch (error) {
console.error(“Error in workflow execution:”, error.message);
callback(error);
}
};
I would really appreciate it if anyone can help me with this.