Hi All
I would like to create a new line item on a deal using the custom code actions in a workflow, I am new to JS.Node but have tried this without any luck, any one that can see what I am doing wrong?
var request = require("request");
exports.main = (event,) => {
var options = {
method: 'POST',
url: 'https://api.hubapi.com/crm/v3/objects/line_items',
qs: {hapikey: process.env.APIKEY},
headers: {accept: 'application/json', 'content-type': 'application/json'},
body: {
properties: {
name: '1 year implementation consultation',
hs_product_id: '191902',
quantity: '2',
price: '6000.00'
}
},
associations:
{ contactIds: [],
companyIds: [],
dealIds: [event.object.objectId],
ownerIds: [] },
json: true
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
});
}
@JStenbaek ,
Are you receiving any errors?
@louischausse might be able to help as I believe he works with node 
@JStenbaek happy to help
yes if you can share the error or any other output that would help.
Please send also a screenshot of your configuration of the custom code action in your workflow
Thanks
No Error massage! but the line item is not created on the deal
Hello @JStenbaek,
On line 3 you have a red alert, what does it have to say?
Thanks for the help this is the error massage.
Hi everyone! 
Just adding a quick update for anyone coming across this thread.
As @karstenkoehler mentioned, HubSpot now offers a native Add line item to Deal workflow action for eligible subscriptions!
This means you can automatically add products from your product library to deals without needing custom code.
If you’re using the API instead, keep in mind that the original example uses legacy API key authentication, which is no longer supported. For current integrations, use private app or OAuth authentication and refer to the latest HubSpot developer documentation.
Hope this helps!
@JStenbaek it seems that the callback is missing at line 3:
exports.main = (event, callback) => {
Also, it seems that in line 13 you are referring to the product id that there is in the sample code in the documentation. Since this product probably doesn’t exist in your portal you will probably end up with an error. You need to change this for an actual product id in your HubSpot product library. You can find this in Settings > Products & Quotes:
hs_product_id: '191902',
Start by fixing this and let me know where it leads you and I could keep continue to help you.
Moderator Note: this post was reviewed for relevancy and optimized for clarity on October 23, 2026. Thank you for your contributions to the HubSpot Community!
Hi @JStenbaek,
I want to share a product update here which might make a custom code action obsolete - it makes automation of line items a lot easier: HubSpot Login and Sign in
Add Line Items to Deals via Workflow Actions
What is it?
You now have access to a new workflow action that lets you automatically add line items to a deal.Within a workflow, you can:
- Select a specific product from your product library
- Set a quantity
- Automatically attach that line item to the deal when the workflow runs
This brings product and pricing logic directly into your automations. No manual deal updates required.
Why does it matter?
Before this, adding products to deals required manual work or post-automation cleanup. Now, you can:
- Fully automate deal setup the moment a trigger fires
- Ensure consistent products and quantities are applied every time
- Reduce human error and save time for sales and ops teams
- Build more advanced revenue workflows (e.g. auto-adding onboarding fees, setup packages, or standard bundles)
This is a huge unlock for automation, especially for teams standardizing how deals are created.
How does it work?
- Create or edit a Deal-based workflow
- Add the new Add line item to Deal action
- Select a product from the product library
- Set the default quantity
- Publish the workflow
When the workflow runs, a line item is created with the selected product and quantity and associated with the Deal automatically.
Who gets it?
Commerce Hub Professional, Commerce Hub Enterprise, Content Hub Starter, Content Hub Professional, Content Hub Enterprise, Marketing Hub Professional, Marketing Hub Enterprise, Data Hub Professional, Data Hub Enterprise, Sales Hub Professional, Sales Hub Enterprise, Service Hub Professional, Service Hub Enterprise, Smart CRM Professional, Smart CRM Enterprise
Best regards