How to send list of objects using single send APi


#1

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"}]
}]
}


#5

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.