Using Custom Coded Actions to create line items

AKoprivec3
Member

Hey, I'm trying to using workflow automation to do some calculation of deal properties and end up creating line items and then a quote. First question would be if this is all doable within Coded automation or if we should look for another provider for this (AWS Lambda for example).


I'm trying to create the line items for the deal using the line items api but it seems to not be working, tested this same code in postman and it worked just fine, any help?

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


exports.main = async (event, callback) => {
  /*****
    Use inputs to get data from any action in your workflow and use it in your code instead of having to use the HubSpot API.
  *****/
	const dealId = event.inputFields['dealId'];

   const hubspotClient = new hubspot.Client({
    accessToken: process.env.SECRET
  });

const properties = {
  "name": "3 year implementation consultation",
  "quantity": "2",
  "price": "6000.00"
};
const SimplePublicObjectInputForCreate = { properties, associations: [{"to":{"id":dealId},"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)
}
0 Upvotes
1 Accepted solution
AKoprivec3
Solution
Member

Hey matt,

 

no error msg. I managed to fix it by using axios and legit have the same code (super woierd). The thing was the original code worked just fine in postman but wouldnt want to add the line items when testing it in coded automation. The limit right now is at 87MB and 12seconds runtime but I'm scared we will hit the limit when I add some logic to calculating the line items. Do you have any experience in just doing chain coded automation and passing the arguments from one to the other or is this something not recommended?

View solution in original post

0 Upvotes
6 Replies 6
MatthiasKunz
Participant | Partner
Participant | Partner

Typically we would probably use an IPaaS for this kind of job but since it is possible there, there is no reason it would not work from coded automation. If you have an error message that would be great and I also find it useful to look at the payload sent to the API to see if there is anything malformed there.

0 Upvotes
AKoprivec3
Solution
Member

Hey matt,

 

no error msg. I managed to fix it by using axios and legit have the same code (super woierd). The thing was the original code worked just fine in postman but wouldnt want to add the line items when testing it in coded automation. The limit right now is at 87MB and 12seconds runtime but I'm scared we will hit the limit when I add some logic to calculating the line items. Do you have any experience in just doing chain coded automation and passing the arguments from one to the other or is this something not recommended?

0 Upvotes
MatthiasKunz
Participant | Partner
Participant | Partner

Hello @AKoprivec3,
that is weird. I'll admit we have done chains before but I would not recommend it, it's a bit hacky and in my experience ends up being high maintenance. I would run the code outside somewhere and just make API calls into Hubspot at that point to get and write information. We often use Make or n8n for these kinds of jobs, for ease of maintaining everything but any place where you can run the code should do the trick.

0 Upvotes
AKoprivec3
Member

Hey @MatthiasKunz 

Is custom coding also an option on those platforms with less memory limitiaions (not familiar with those platoforms) or would something like AWS Lambda work fine here aswell? I know this is a bit out of topic but thank you for your help on this

0 Upvotes
MatthiasKunz
Participant | Partner
Participant | Partner

Hey @AKoprivec3 

to be honest, Lambda should work, but I haven't done much with Lambda, so I can't speak too much to that. 
If you want to really have no limitation, get a self-hosted n8n instance on a docker somewhere convenient and you should be able to do whatever your setup is able to cope with. Make would have limitations and timeouts although a bit more generous at 40 seconds last I checked.

0 Upvotes
Jaycee_Lewis
Thought Leader

Hi, @AKoprivec3 👋 Welcome to our community! Thanks for including your code example. Are you getting any errors returned? Also, is your code hitting the 20-second limit for completion? “Custom code actions must finish running within 20 seconds”.

 

Hey, @ChrisoKlepke @miljkovicmisa @HFisher7 @MatthiasKunz have you been successful with anything similar recently?

 

Thank you for taking a look! — Jaycee





loop


Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.

Learn More




0 Upvotes