# Updating Line Items via Custom Code Workflow Step

**URL:** <https://community.hubspot.com/t/updating-line-items-via-custom-code-workflow-step/125239>\
**Category:** APIs & Integrations\
**Tags:** workflows\
**Created:** [January 31, 2025, 9:48pm UTC](https://community.hubspot.com/t/updating-line-items-via-custom-code-workflow-step/125239 "2025-01-31T21:48:24Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![DHills48](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@DHills48](https://community.hubspot.com/u/DHills48)\
**Post date:** [January 31, 2025, 9:48pm UTC](https://community.hubspot.com/t/updating-line-items-via-custom-code-workflow-step/125239/1 "2025-01-31T21:48:24Z")

</div>

Hello,  
I’m trying to update past line items with specific checkboxes so I can easily use them for reports and calculate commissions.  
Here’s GitHub to the code I’m using.

> <https://github.com/MicroStomatid/HubSpotHelp/commit/65fbeeeb94b3d059069ecfdc84399939a080c655>

The code runs, but does not like the “.basicApi” on line 21. Does this update method not work on line items? I was able to use this method to update tickets and meetings.  
Shout out to Zach Klein for showing me the the method I’ve been able to use.

---

<div class="post-metadata">

**Author:** ![WesQ](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wesq/32/17184_2.png) [@WesQ](https://community.hubspot.com/u/WesQ)\
**Post date:** [February 1, 2025, 6:19am UTC](https://community.hubspot.com/t/updating-line-items-via-custom-code-workflow-step/125239/2 "2025-02-01T06:19:11Z")

</div>

Hello @DHills48

The error message: TypeError: Cannot read properties of undefined (reading ‘basicApi’) usually means there is something wrong with the previous object which is “line\_items”.

In the HubSpot line items are accessed via hubspotClient.crm. **lineItems** instead of hubspotClient.crm. **line\_items**.

Reference: [https://developers.hubspot.com/docs/reference/api/crm/objects/line-items#basic](https://developers.hubspot.com/docs/reference/api/crm/objects/line-items#basic)

![](https://d2qpr2jzcazej7.cloudfront.net/original/3X/7/0/707280cae4a04999540e3e920e717c53f28d0a56.png)Was I able to help answer your question? Help the community by **marking it as a solution.**

---

<div class="post-metadata">

**Author:** ![DHills48](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@DHills48](https://community.hubspot.com/u/DHills48)\
**Post date:** [February 3, 2025, 11:53pm UTC](https://community.hubspot.com/t/updating-line-items-via-custom-code-workflow-step/125239/3 "2025-02-03T23:53:02Z")

</div>

@WesQ Thank you! I’m passed the first hurdle. Now it the error I’m getting is the “lineItemID is null or undefined”.  
I take that team it’s not getting line item’s id/record number, which is surprising to me because I am pulling it in as an input field. I also updated my code to match the errors specification.  
I updated GitHub with the latest code I’m using.

 ![DHills48_0-1738626649376.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/9/6/96288a1eeea3baf07c204e12903ab4d972b33b4f.png)

![DHills48_1-1738626735574.png](https://d2qpr2jzcazej7.cloudfront.net/optimized/3X/a/8/a822798ceccefe00ccdec00344f8c60c6dbf7bab_2_690x58.png)

---

<div class="post-metadata">

**Author:** ![WesQ](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wesq/32/17184_2.png) [@WesQ](https://community.hubspot.com/u/WesQ)\
**Post date:** [February 4, 2025, 4:14am UTC](https://community.hubspot.com/t/updating-line-items-via-custom-code-workflow-step/125239/4 "2025-02-04T04:14:26Z")

</div>

The first argument required by the lineItems.basicApi.update is the lineItemId that you want to update.

const apiResponse = await hubspotClient.crm.lineItems.basicApi.update( **lineItemId** , SimplePublicObjectInput, idProperty);

On your code you are using **record\_id** as the first argument and its value is undefined because as seen on your picture attached you are getting the record Id and giving it a name of hs\_object\_id. If you change it to record\_id it should work.

**Reference:**

[https://developers.hubspot.com/docs/reference/api/crm/objects/line-items#patch-%2Fcrm%2Fv3%2Fobjects%2Fline\_items%2F%7Blineitemid%7D](https://developers.hubspot.com/docs/reference/api/crm/objects/line-items#patch-%2Fcrm%2Fv3%2Fobjects%2Fline_items%2F%7Blineitemid%7D)

Let me know if you need more help. And please mark my answer as solution. Thank you!

---

<div class="post-metadata">

**Author:** ![DHills48](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@DHills48](https://community.hubspot.com/u/DHills48)\
**Post date:** [February 5, 2025, 12:04am UTC](https://community.hubspot.com/t/updating-line-items-via-custom-code-workflow-step/125239/5 "2025-02-05T00:04:42Z")

</div>

Hi @WesQ it’s still returning an error.  
If I understood correctly, I was supposed to change the input field from “hs\_object\_id” to “record\_id” correct?  
I saw in the documentation it said the “Scope” was e-Commerce. It should work as long as it as crm.objects.line\_items.write and .read, right?

 ![DHills48_0-1738711929650.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/7/0/70fd1776257075dd38edafb003944686a69ca245.png)

---

<div class="post-metadata">

**Author:** ![WesQ](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wesq/32/17184_2.png) [@WesQ](https://community.hubspot.com/u/WesQ)\
**Post date:** [February 5, 2025, 3:02am UTC](https://community.hubspot.com/t/updating-line-items-via-custom-code-workflow-step/125239/6 "2025-02-05T03:02:02Z")

</div>

@DHills48

Yes, you correctly changed the input field name to match what’s inside the code.

For the scope, the granular scope "crm.objects.line\_items.write ", would be enough. Dont need the e-commerce.

Can you post the new error you are getting now?

---

<div class="post-metadata">

**Author:** ![DHills48](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@DHills48](https://community.hubspot.com/u/DHills48)\
**Post date:** [February 5, 2025, 10:10pm UTC](https://community.hubspot.com/t/updating-line-items-via-custom-code-workflow-step/125239/7 "2025-02-05T22:10:25Z")

</div>

@WesQ Yep! Here’s the full error.

 ![DHills48_0-1738793370231.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/f/b/fb30cdc0d9191429120225e01fc3b31d35c66b22.png)

---

<div class="post-metadata">

**Author:** ![WesQ](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wesq/32/17184_2.png) [@WesQ](https://community.hubspot.com/u/WesQ)\
**Post date:** [February 6, 2025, 8:55am UTC](https://community.hubspot.com/t/updating-line-items-via-custom-code-workflow-step/125239/8 "2025-02-06T08:55:10Z")

</div>

@DHills48

With that error, it is most probable that you are not getting the lineItemId value correctly. How are you getting the line item Id that you want to update?

To debug this I would usually get a sample line item id that I want to update from the CRM UI like this:

 ![WesQ_1-1738831881793.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/e/7/e785f3b82b06fd75cfd46521ef356ec15e039a21.png)

Then plug the string value as the value for the lineItemId like shown in line 7:

 ![WesQ_0-1738831756820.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/2/4/24df357a84d0537cc0d3a42bb866550eb4433e3d.png)

Then use the “Test” button to see if it works:

 ![WesQ_2-1738831990837.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/3/7/37f4f36fefab68ac3280960a6cfb8c517a753904.png)

It will most probably work. Then next question would be, how are you going to get the line Id you want to update. Can you show me your workflow trigger? Is this workflow deal based?

---

<div class="post-metadata">

**Author:** ![DHills48](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@DHills48](https://community.hubspot.com/u/DHills48)\
**Post date:** [February 10, 2025, 11:04pm UTC](https://community.hubspot.com/t/updating-line-items-via-custom-code-workflow-step/125239/9 "2025-02-10T23:04:54Z")

</div>

Hi @WesQ,  
Sorry for the delay. Thank you for the troubleshooting example!  
Yes, the workflow is deal based. Here’s a screenshot of the enrollment criteria.

 ![DHills48_0-1739228623811.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/6/7/673fc79a140429384cbe235c85a174dd43e21277.png)

---

<div class="post-metadata">

**Author:** ![WesQ](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wesq/32/17184_2.png) [@WesQ](https://community.hubspot.com/u/WesQ)\
**Post date:** [February 11, 2025, 8:09am UTC](https://community.hubspot.com/t/updating-line-items-via-custom-code-workflow-step/125239/10 "2025-02-11T08:09:21Z")

</div>

@DHills48

As a recap, what we need to fetch first are the lineItemIds to update right?

And right now since we have a deal based workflow here, I believe there is no currently available “workflow action” that can get value of all the line items associated. If your deals have a 1 to 1 relationship to line items you can use “Property to include in code” in the action, however you most probably have multiple line items associated with the enrolled deal so this won’t work.

**Solution:**

In your custom code action, you need to first

1. Fetch all the associated line items you need to update.

2. Loop through each line item and use API to update each individually.

See section “Retrieve Associated Records” in the reference below on how to do that.

**Reference:**

> **[Associate records - HubSpot docs](https://developers.hubspot.com/docs/api-reference/latest/crm/associations/associate-records/guide)**
>
> Use the associations API to create, manage, and remove associations between CRM records.

![](https://d2qpr2jzcazej7.cloudfront.net/original/3X/7/0/707280cae4a04999540e3e920e717c53f28d0a56.png)Was I able to help answer your question? Help the community by **marking it as a solution.**
