<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Create Line Items for a Deal during a Workflow Custom Code Block in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Create-Line-Items-for-a-Deal-during-a-Workflow-Custom-Code-Block/m-p/779824#M62989</link>
    <description>&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 10 Apr 2023 09:34:38 GMT</pubDate>
    <dc:creator>BHooker</dc:creator>
    <dc:date>2023-04-10T09:34:38Z</dc:date>
    <item>
      <title>Create Line Items for a Deal during a Workflow Custom Code Block</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Create-Line-Items-for-a-Deal-during-a-Workflow-Custom-Code-Block/m-p/779255#M62937</link>
      <description>&lt;P&gt;Goal is to add a set of line_items to a deal using a workflow custom code block. &amp;nbsp;A set of SKUs will be passed in. &amp;nbsp;Approach is to add the line items, and then associate them with the deal. &amp;nbsp;The Products already exist in the product object, so we can reference hs_sku or hs_product_id as required.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Getting an error when running the crm.line_items.create method.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It looks like the crm.line_items methods are being blocked or erroring.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Can anyone assist?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Details:&lt;/P&gt;&lt;P&gt;Workflow: After deal created, this workflow and action is run&lt;/P&gt;&lt;P&gt;Language: node.js 16.x&lt;/P&gt;&lt;P&gt;Private App: has read and write access to crm.deals and crm.line_items&amp;nbsp;&lt;/P&gt;&lt;P&gt;Client: Hubspot Client v8&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Custom Code:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;const hubspot = require('@hubspot/api-client');

exports.main = async (event, callback) =&amp;gt; {

  const skus = event.inputFields['expedition_skus_specification'];
  const dealId = event.object.objectId;
  
  console.log('Product SKUs to add to the deal: ' + skus);
  console.log('Deal ID: ' + dealId);

  const hubspotClient = new hubspot.Client({
    accessToken: process.env.ProductConfiguratorKey
  });

  console.log('Reading deals properties');  
  let amount;
  try {
    const ApiResponse = await hubspotClient.crm.deals.basicApi.getById(event.object.objectId, ["amount"]);
    amount = ApiResponse.properties.amount;
    console.log('Retrieved deal amount is: ' + amount);
  } catch (err) {
    console.error(err);
    throw err;
  }
  
  console.log('Creating a line item');  
  const lineItemInput = {
    name: 'Main product',
    quantity: 1,
    price: 140000.0
    //hs_product_id: hs_product_id // Replace with the existing hs_product_id
    // other line item properties as needed
  }; 

  //hubspotClient.crm.line_items.basicApi.create(lineItemInput)
  hubspotClient.crm.line_items.create(lineItemInput)
    .then((createdLineItem) =&amp;gt; {
      console.log('Created line item with ID:', createdLineItem.id);
      // do something with the created line item
    })
    .catch((err) =&amp;gt; {
      console.error(err);
    });

  callback({
    outputFields: {
      expedition_skus_returned: skus
    }
  });
}&lt;/LI-CODE&gt;&lt;P&gt;Error:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;2023-04-07T11:10:49.490Z	INFO	Product SKUs to add to the deal: undefined
2023-04-07T11:10:49.490Z	INFO	Deal ID: 1127594795
2023-04-07T11:10:49.491Z	INFO	Reading deals properties
2023-04-07T11:10:50.832Z	INFO	Retrieved deal amount is: 30000
2023-04-07T11:10:50.832Z	INFO	Creating a line item
2023-04-07T11:10:50.889Z	ERROR	Unhandled Promise Rejection 	{"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"TypeError: Cannot read properties of undefined (reading 'create')","reason":{"errorType":"TypeError","errorMessage":"Cannot read properties of undefined (reading 'create')","stack":["TypeError: Cannot read properties of undefined (reading 'create')","    at Object.exports.main (/var/task/file.js:36:32)","    at processTicksAndRejections (node:internal/process/task_queues:96:5)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: TypeError: Cannot read properties of undefined (reading 'create')","    at process.&amp;lt;anonymous&amp;gt; (file:///var/runtime/index.mjs:1188:17)","    at process.emit (node:events:513:28)","    at emit (node:internal/process/promises:140:20)","    at processPromiseRejections (node:internal/process/promises:274:27)","    at processTicksAndRejections (node:internal/process/task_queues:97:32)"]}
Unknown application error occurred
Runtime.Unknown

Memory: 25/128 MB
Runtime: 1599.94 ms&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2023 11:25:24 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Create-Line-Items-for-a-Deal-during-a-Workflow-Custom-Code-Block/m-p/779255#M62937</guid>
      <dc:creator>BHooker</dc:creator>
      <dc:date>2023-04-07T11:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: Create Line Items for a Deal during a Workflow Custom Code Block</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Create-Line-Items-for-a-Deal-during-a-Workflow-Custom-Code-Block/m-p/779822#M62987</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/534201"&gt;@BHooker&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should use func `&lt;STRONG style="font-family: inherit;"&gt;crm.lineItems.create`&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/HubSpot/hubspot-api-nodejs/blob/master/codegen/crm/line_items/apis/BasicApi.ts#L70" target="_blank" rel="noopener"&gt;https://github.com/HubSpot/hubspot-api-nodejs/blob/master/codegen/crm/line_items/apis/BasicApi.ts#L70&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And you should change `lineItemInput`.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/HubSpot/hubspot-api-nodejs/blob/master/codegen/crm/line_items/models/SimplePublicObjectInput.ts#L14" target="_blank" rel="noopener"&gt;https://github.com/HubSpot/hubspot-api-nodejs/blob/master/codegen/crm/line_items/models/SimplePublicObjectInput.ts#L14&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is sample code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;// /crm/line_items/models/SimplePublicObjectInput
const lineItemInput = {
  properties: {
    name: 'Main product',
    quantity: 1,
    price: 140000.0
  },
};
hubspotClient.crm.lineItems.basicApi.create(lineItemInput)
.then((createdLineItem) =&amp;gt; {
  // do something with the created line item
})
.catch((err) =&amp;gt; {
  console.error(err);
});&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2023 09:30:34 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Create-Line-Items-for-a-Deal-during-a-Workflow-Custom-Code-Block/m-p/779822#M62987</guid>
      <dc:creator>skimura</dc:creator>
      <dc:date>2023-04-10T09:30:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create Line Items for a Deal during a Workflow Custom Code Block</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Create-Line-Items-for-a-Deal-during-a-Workflow-Custom-Code-Block/m-p/779824#M62989</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2023 09:34:38 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Create-Line-Items-for-a-Deal-during-a-Workflow-Custom-Code-Block/m-p/779824#M62989</guid>
      <dc:creator>BHooker</dc:creator>
      <dc:date>2023-04-10T09:34:38Z</dc:date>
    </item>
    <item>
      <title>Re: Create Line Items for a Deal during a Workflow Custom Code Block</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Create-Line-Items-for-a-Deal-during-a-Workflow-Custom-Code-Block/m-p/1259824#M87180</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/534201"&gt;@BHooker&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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:&amp;nbsp;&lt;A href="https://app-eu1.hubspot.com/l/product-updates/?rollout=281984" target="_blank"&gt;https://app-eu1.hubspot.com/l/product-updates/?rollout=281984&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;Add Line Items to Deals via Workflow Actions&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;What is it?&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;You now have access to a new workflow action that lets you automatically add line items to a deal.Within a workflow, you can:&lt;/EM&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;EM&gt;Select a specific product from your product library&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;Set a quantity&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;Automatically attach that line item to the deal when the workflow runs&lt;/EM&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;EM&gt;This brings product and pricing logic directly into your automations. No manual deal updates required.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;Why does it matter?&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Before this, adding products to deals required manual work or post-automation cleanup. Now, you can:&lt;/EM&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;EM&gt;Fully automate deal setup the moment a trigger fires&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;Ensure consistent products and quantities are applied every time&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;Reduce human error and save time for sales and ops teams&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;Build more advanced revenue workflows (e.g. auto-adding onboarding fees, setup packages, or standard bundles)&lt;/EM&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;EM&gt;This is a huge unlock for automation, especially for teams standardizing how deals are created.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;How does it work?&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;EM&gt;Create or edit a Deal-based workflow&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;Add the new Add line item to Deal action&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;Select a product from the product library&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;Set the default quantity&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;Publish the workflow&lt;/EM&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;EM&gt;When the workflow runs, a line item is created with the selected product and quantity and associated with the Deal automatically.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;Who gets it?&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;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&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2026 05:20:32 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Create-Line-Items-for-a-Deal-during-a-Workflow-Custom-Code-Block/m-p/1259824#M87180</guid>
      <dc:creator>karstenkoehler</dc:creator>
      <dc:date>2026-03-18T05:20:32Z</dc:date>
    </item>
  </channel>
</rss>

