Create line items with associations in Workflows

Hi all,
I am running into a strange problem and hoping someone can shed some light on it.
I am trying to create a line item using Workflows. This line item is to have an assocation to a deal.
Below is a copy of my code with my parameters scrubbed.

 const properties = {
 "name": "test name",
 "hs_product_id": product_id,
 "quantity": "1",
 "price": "100.00"
};
const SimplePublicObjectInputForCreate = { properties, associations: [{"to":{"id": deal_id},"types":[{"associationCategory":"HUBSPOT_DEFINED","associationTypeId":20}]}] };

try {
 const apiResponse = await hubspotClient.crm.lineItems.basicApi.create(SimplePublicObjectInputForCreate);
 console.log(JSON.stringify(apiResponse, null, 2));
} catch (e) {
 e.message === 'HTTP request failed'
 ? console.error(JSON.stringify(e.response, null, 2))
 : console.error(e)
}

I can run this code through the endpoints on the hubspot docs pages and it all works fine. However, when running it in workflows, the line item gets created but not associated.
I know the work around is just to run the associations api afterwards but I am wondering if I am using the line items api incorrectly.
Any help is greatly appreciated.
Thanks,
Pauric

Hi @PMcConnell,

Thanks for reaching out to the Community!

I wanted to invite our subject matter experts to see if they have insight.

Hi @louischausse, @JBeatty, @ChrisoKlepke - Do you have any advice for @PMcConnell?

Thank you!

Best,

Kristen

Hi @PMcConnell,

This looks like an error with the HubSpot API client, looking at the logs for the token the client simply isnt sending the associations portion of the body:

I would recommend using axios as a work around, that way it stays as a single api call, you could do that by doing the following:

const axios = require('axios').default;
exports.main = async (event, callback) => {
 const client = axios.create({
 baseURL: 'https://api.hubapi.com',
 headers: {
 accept: 'application/json',
 Authorization: `Bearer ${process.env.APPTOKEN}`
 }
 });

 const properties = {
 "name": "test name",
 "hs_product_id": 1579739513,
 "quantity": "1",
 "price": "100.00"
 };
 await client.post(`/crm/v3/objects/line_items`, 
 { properties, associations: [{ "to": { "id": event.object.objectId }, "types": [{ "associationCategory": "HUBSPOT_DEFINED", "associationTypeId": 20 }] }] });

}

Best,

Hi Everyone,

I work for a HubSpot Diamond Partner. We have developed an app for the marketplace that aims to solve the issue of displaying associated line items. Currently, line items associated with deals remain hidden in other relevant objects. This app bridges the gap by introducing CRM cards that unveil line item lists within associated objects.

We are seeking beta testers who can try our app at no cost, provide valuable feedback, and assist us in enhancing the overall usability of the product.

:backhand_index_pointing_right: Join the Beta Test → Installation link :link:

:backhand_index_pointing_right: How it works document → PDF

While you’re here, don’t forget to check out our other apps in the HubSpot Marketplace for more helpful solutions!

Cheers!