# Custom code action, create line item on a deal

**URL:** <https://community.hubspot.com/t/custom-code-action-create-line-item-on-a-deal/38183>\
**Category:** APIs & Integrations\
**Tags:** workflows, professional, object\
**Created:** [May 31, 2021, 8:39pm UTC](https://community.hubspot.com/t/custom-code-action-create-line-item-on-a-deal/38183 "2021-05-31T20:39:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![JStenbaek](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jstenbaek/32/32521_2.png) [@JStenbaek](https://community.hubspot.com/u/JStenbaek)\
**Post date:** [May 31, 2021, 8:39pm UTC](https://community.hubspot.com/t/custom-code-action-create-line-item-on-a-deal/38183/1 "2021-05-31T20:39:25Z")

</div>

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?

```lia-code-sample
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);
 });
}

```

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [June 1, 2021, 3:18pm UTC](https://community.hubspot.com/t/custom-code-action-create-line-item-on-a-deal/38183/2 "2021-06-01T15:18:27Z")

</div>

@JStenbaek ,

Are you receiving any errors?

@louischausse might be able to help as I believe he works with node 😀

---

<div class="post-metadata">

**Author:** ![louischausse](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/louischausse/32/18067_2.png) [@louischausse](https://community.hubspot.com/u/louischausse)\
**Post date:** [June 1, 2021, 4:06pm UTC](https://community.hubspot.com/t/custom-code-action-create-line-item-on-a-deal/38183/3 "2021-06-01T16:06:36Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![JStenbaek](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jstenbaek/32/32521_2.png) [@JStenbaek](https://community.hubspot.com/u/JStenbaek)\
**Post date:** [June 1, 2021, 7:11pm UTC](https://community.hubspot.com/t/custom-code-action-create-line-item-on-a-deal/38183/4 "2021-06-01T19:11:57Z")

</div>

No Error massage! but the line item is not created on the deal

 ![Screenshot 2021-06-01 at 21.10.08.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/9/9/9981a0cbff7078b01cd90b6609dda0a91ea80420.png)

 ![Screenshot 2021-06-01 at 21.09.14.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/9/d/9d43d9eb4aac05577aee4f90ab37d8147addef46.png)

 ![Screenshot 2021-06-01 at 21.09.05.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/5/e/5ef266c1acc0d886cec6a89f0001f9ca7664f8c1.png)

 ![Screenshot 2021-06-01 at 21.08.46.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/d/df1c6584ac14853dd8270edcbf40f5e6d88254ad.png)

---

<div class="post-metadata">

**Author:** ![louischausse](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/louischausse/32/18067_2.png) [@louischausse](https://community.hubspot.com/u/louischausse)\
**Post date:** [June 1, 2021, 8:48pm UTC](https://community.hubspot.com/t/custom-code-action-create-line-item-on-a-deal/38183/5 "2021-06-01T20:48:11Z")

</div>

Hello @JStenbaek,

On line 3 you have a red alert, what does it have to say?

---

<div class="post-metadata">

**Author:** ![JStenbaek](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jstenbaek/32/32521_2.png) [@JStenbaek](https://community.hubspot.com/u/JStenbaek)\
**Post date:** [June 2, 2021, 7:51am UTC](https://community.hubspot.com/t/custom-code-action-create-line-item-on-a-deal/38183/6 "2021-06-02T07:51:42Z")

</div>

Thanks for the help this is the error massage.

 ![Screenshot 2021-06-02 at 09.49.23.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/2/a/2ad13339cfe29fcf1ba2c6cacc78efbdccb272ca.png)

---

<div class="post-metadata">

**Author:** ![louischausse](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/louischausse/32/18067_2.png) [@louischausse](https://community.hubspot.com/u/louischausse)\
**Post date:** [June 2, 2021, 12:40pm UTC](https://community.hubspot.com/t/custom-code-action-create-line-item-on-a-deal/38183/7 "2021-06-02T12:40:40Z")

</div>

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](https://developers.hubspot.com/docs/api-reference/latest/overview).

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!_

---

<div class="post-metadata">

**Author:** ![karstenkoehler](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/karstenkoehler/32/68554_2.png) [@karstenkoehler](https://community.hubspot.com/u/karstenkoehler)\
**Post date:** [March 18, 2026, 5:21am UTC](https://community.hubspot.com/t/custom-code-action-create-line-item-on-a-deal/38183/8 "2026-03-18T05:21:16Z")

</div>

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](https://app-eu1.hubspot.com/l/product-updates/?rollout=281984)

_ **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?** _

1. _Create or edit a Deal-based workflow_
2. _Add the new Add line item to Deal action_
3. _Select a product from the product library_
4. _Set the default quantity_
5. _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
