APIs & Integrations

Bharat_Challapa
Member

How to send list of objects using single send APi

SOLVE

Hi,

How to send list of objects to email template using custom property in single send api. Please go through below example template.

{{custom.RecommendationSteps }}

{% for item in custom.RecommendationSteps %}

Topic Name: {{item.TopicName}}

{% endfor %}

{"emailId":"XXXXXX","message":{"to":"XXXXXXXXXX@XXXX.xxx"},"contactProperties":,"customProperties":[
{"name":"RecommendationSteps", "value":[{"name":"TopicName", "value":"TopicNamexyz"},{"name":"TopicName", "value":"xyz"}]
}]
}

0 Upvotes
1 Accepted solution
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

How to send list of objects using single send APi

SOLVE

Welcome, @Bharat_Challapally!

At this time, custom properties passed via the single send API cannot be used in HubL for loops.

The reasoning is the same as it is for if statements — all HubL logic executes before custom properties and tokens are populated.

Here are some related topics:

The team understands this is a pain point and hopes to support greater HubL flexibility in email templates in the future.

In the meantime, the best way to surface multiple property values in the same template is to pre-render the values in an HTML table and pass the HTML into the custom token.

Something like:

{{custom.Table}}

{
     "emailId":"XXXXXX",
     "message": {"to":"XXXXXXXXXX@XXXX.xxx"},
     "contactProperties":[],
     "customProperties":[
          {"name":"Table", "value": "<div><ul><li>TopicNameABC<\/li><li>TopicNameXYZ<\/li><\/ul><\/div>"
          }
     ]
}

While this method works, I recognize it isn't an ideal solution and places the burden on you as the developer.

Isaac Takushi

Associate Certification Manager

View solution in original post

0 Upvotes
3 Replies 3
DMorrison7
Member

How to send list of objects using single send APi

SOLVE

I am also wondering if any work has been done to resolve this problem?

 

Same questions as above:

  • Has any work been done to improve the HubL flexibility in email templates since this post was made in 2018?
  • Is any work to improve the HubL flexibility in email templates planned for the next month? 6 months?

This puts the burden on the developer to write custom html and send it via custom properties to the email template. This is especially burdensome to work across marketing/development departments any time a small change needs to made to an email template. I greatly appreciate any response in regards to this.

IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

How to send list of objects using single send APi

SOLVE

Welcome, @Bharat_Challapally!

At this time, custom properties passed via the single send API cannot be used in HubL for loops.

The reasoning is the same as it is for if statements — all HubL logic executes before custom properties and tokens are populated.

Here are some related topics:

The team understands this is a pain point and hopes to support greater HubL flexibility in email templates in the future.

In the meantime, the best way to surface multiple property values in the same template is to pre-render the values in an HTML table and pass the HTML into the custom token.

Something like:

{{custom.Table}}

{
     "emailId":"XXXXXX",
     "message": {"to":"XXXXXXXXXX@XXXX.xxx"},
     "contactProperties":[],
     "customProperties":[
          {"name":"Table", "value": "<div><ul><li>TopicNameABC<\/li><li>TopicNameXYZ<\/li><\/ul><\/div>"
          }
     ]
}

While this method works, I recognize it isn't an ideal solution and places the burden on you as the developer.

Isaac Takushi

Associate Certification Manager
0 Upvotes
webmaestro
Member

How to send list of objects using single send APi

SOLVE

In regards to this:

The team understands this is a pain point and hopes to support
greater HubL flexibility in email templates in the future.

Some questions:

  • Has any work been done to improve the HubL flexibility in email templates since this post was made in 2018?
  • Is any work to improve the HubL flexibility in email templates planned for the next month? 6 months?