Custom Coded Workflow - find line item associations

I have some experience in R but nearly none in JavaScript/Python. In scowering the internet for hours this is the best I’ve came up with with finding line item associations with a deal. I want to be able to use the line items and their information later in the workflow to attach to a new deal.

What am I missing?

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

exports.main = (event, callback) => {

 const hubspotClient = new hubspot.Client({
 apiKey: process.env.hapikey
 });

 // First, make a call to get deal associations 
 hubspotClient.crm.deals.associationsApi.getAll(event.object.objectId, 'line_item').then((results) => {
 let lineItemPromises = results.body.results.map(item => {
 // For each line item, get its details
 return hubspotClient.crm.lineItems.basicApi.getById(item.id, ['amount']).then(results => {
 return results.body; // Return the details of the line item
 }).catch(err => {
 console.error(`Error fetching details for line item ${item.id}:`, err.message);
 return null; // Return null or handle as appropriate for your needs
 });
 });

 // Resolve all promises to get details of each line item
 Promise.all(lineItemPromises).then(lineItemDetails => {
 console.log(lineItemDetails); // Log the details of all line items

 // Further processing can be done here with lineItemDetails
 // For example, filtering high-value line items, aggregating data, etc.

 callback({}); // Complete the function
 }).catch(err => {
 console.error('Error processing line items:', err.message);
 callback({}); // Complete the function, consider passing error details
 });

 }).catch(err => {
 console.error('Error fetching line item associations:', err.message);
 callback({}); // Complete the function, consider passing error details
 });
}

Hi @AOber and Happy New Year!!!
Thank you for reaching out to the Community!
For information, I’d like to share this documentation on the subject “Custom code workflow actions”.
I understand that you are trying to find line item associations via a custom coded workflow action. If that’s not the case, please let me know.
I’ll be glad to put you in touch with some of our Community Members and some of our Top Experts on this matter:
Hi @AKoprivec3, @MatthiasKunz, @JStenbaek, @louischausse, @Sylg and, @kierana do you have suggestions to help @AOber, please?
Also, if anybody else has anything to add and/or share, please feel free to join in the conversation :)
Thank you so much and have a fantastic day!
Best,
Bérangère

Hey @BérangèreL & @AOber thanks for the mention (hopped on another acc),
There a couple of potential issues I see here but I’d be great if I could see the error you’re having when testing this.
Also I’m guessing this is a deal based workflow since you’re using the event’s object objectId as the dealId correct?
I don’t like the associations API too much (its arguably better though) so I usualy use the Deal API if I’m trying to get associated Line Items from the deal and then batch read the IDs of the Line items to get their details.
When I’ll see you’re error logs I might be able to help you better here.
Best,
Anze