Integrating Line Item Properties in Emails

Hello,

I’m trying to create a workflow for where a deal is “Closed - Won” an email is triggered to be sent to the customer, which acts as a confirmation email. After which, said line items are sent via internal email to our logistics team for fulfillment.

I want the email to show the line items that are part of their respective deal, but Line Items are not considered a Deal Property.

I tried creating a custom module to be used in the email template using this code:

{% email_each list="deal.line_items" item="line_item" %} 
 {{line_item}}
{% end_email_each %}

However when I try to save the email for automation, I get the following error message:

YEnergy_1-1677190383336.png

Can anyone tell me where I’ve gone wrong and how I can fix my problem?

Thanks in advance!

One way to achieve this is by using a custom module in your email template, as you’ve mentioned. However, the code you provided may not work as expected since the “line_item” variable is not a property on its own, but rather a collection of properties that make up each line item.
To display the line item properties in your email, you can use the following code:

{% for line_item in deal.line_items %}
 {{ line_item.product_id }} - {{ line_item.quantity }} - {{ line_item.price }}
{% endfor %}

In this example, I’ve assumed that each line item has properties for “product_id”, “quantity”, and “price”, which you can replace with the actual property names for your line items.

This code uses a for loop to iterate through each line item in the “deal.line_items” collection, and displays the relevant properties for each line item. You can customize the formatting and layout of the line items as needed.

Once you’ve added this custom module to your email template, you can set up your workflow to trigger the email when a deal is “Closed - Won”, and include the line item properties as needed.
Thanks & Regards
Himanshu Rauthan

Hi @himanshurauthan,

thanks for the reply! I have the same problem.
Trying to insert the custom code you entered inside a custom form I get nothing back.

The deal is associated with the contact, but still I can’t read the associated line_items.

Do you have any suggestions on this?

Thanks in advance.

Regards
Gianmarco

Hi @YEnergy @GianVentura
I ran into the same issue a couple of weeks ago. What I’ve learned so far from the HubSpot support team is that the ecomm brige sunset impacted the use of line items, so there’s no direct approach to call the {{deal.line_items.properties}}
I’ve also tried the associations API via a custom module and had no luck. However, I came up with a workaround involving a custom property and some Python code (I’m no developer, but I got it working).
Here are the steps:

  1. Create a rich text property for the object (I’m using a deal, but can also work for contacts)
  2. Build an array of your line items (e.g. product name, quantity, etc.) and send it to the rich text property (either with the create or update endpoints for the corresponding object).
  3. Either create a custom module or use a personalization token to call the property’s value to display in the email.

Hope it helps!
Best
Hector

Found this to work for automated and regular emails.

<ul>
{% email_each list="deal.line_items" item="line_item" %}
<li>
<p>{{ line_item.name }}</p>
<p>QTY: {{ line_item.quantity }}</p>
<p>{{ line_item.price }}</p>
</li>
{% endemail_each %}
</ul>

Hello @JPereira2 ,
Thank you for your comment, this worked for me also after some failed attempts at other code structures.
Thanks @BérangèreL for sending me to this thread.

I have the same problem, but with an internal email notifcation that I want to send once a playbook has been filled out. I dont seem to be able to get all line items, just one. Any help appreciated.