APIs & Integrations

COtani
Member

Single Send Api html + Hubl: For Loop not rendering correctly

SOLVE

I'm using the single-send-api with a for loop but the for loop is not working as expected. I used the example in the documentation and added an additional custom property to show that the single custom properties at the main level works, but the array property using a for loop is not working. 

https://developers.hubspot.com/docs/api/marketing/single-send-api

 

Note: when I render the same email in python using jinja2 the for loop works as expected.

 

In the design preview the For loop {{ variables }} do not show up in the preview

COtani_0-1716583296751.png

 

 

Here is the acutal email received that was sent through the api, the property outisde the loop works but not the array for loop properties:

COtani_1-1716582759258.png

 

Here is the template (I used the example in the documentation and it works fine in python rendered usinng Jinja2):

 

 

<!--
    templateType: email
    isAvailableForNewContent: true
-->
<!doctype html>
<html>
  <head>
    <title>test</title>
  </head>
  <body>
  <p>
    Thanks for your recent purchase! Here are the details of the items you'll be receiving:
  </p>
  <p>
    Testing a custom value outside the for loop: {{ custom.test_key }}
  </p>
  <ul>
    {% for item in custom.exampleArray %}
      <li>First key: {{ item.firstKey }}, Second key: {{item.secondKey}}</li>
    {% endfor %}  
  </ul>
    <p id="footer">
      {{ site_settings.company_name }}&nbsp;
      {{ site_settings.company_street_address_1 }}&nbsp;
      {{ site_settings.company_street_address_2 }}&nbsp;
      {{ site_settings.company_city }}&nbsp;
      {{ site_settings.company_state }}&nbsp;
      {{ site_settings.company_zip }}&nbsp;
      {{ site_settings.company_country }}&nbsp;
      <br/>
      You received this email because you are subscribed to {{ subscription_name }} from {{ site_settings.company_name }}.
      <br/>
      <a class="hubspot-mergetag" data-unsubscribe="true" href="{{ unsubscribe_link }}">Update your email preferences</a> to choose the types of emails you receive.
      <br/>
      <a class="hubspot-mergetag" data-unsubscribe="true" href="{{ unsubscribe_link_all }}">Unsubscribe from all future emails.</a>
    </p>
  </body>
</html>

 

 

 

Here is the json data

 

 

    data = {
        "emailId": 168429014623,
        "message": {
            "to": "test@test.com",
        },
        "customProperties": {
            'test_key':'test_value',
            "exampleArray": [
                {"firstKey": "someValue", "secondKey": "anotherValue"},
                {"firstKey": "value1", "secondKey": "value2"}
            ]
        }
    }

 

 

 

0 Upvotes
1 Accepted solution
COtani
Solution
Member

Single Send Api html + Hubl: For Loop not rendering correctly

SOLVE

I found my error. It was in the documentation but I overlooked the note:

 

I needed to add this to the template for it to work:

         isEnabledForEmailV3Rendering: true

View solution in original post

0 Upvotes
1 Reply 1
COtani
Solution
Member

Single Send Api html + Hubl: For Loop not rendering correctly

SOLVE

I found my error. It was in the documentation but I overlooked the note:

 

I needed to add this to the template for it to work:

         isEnabledForEmailV3Rendering: true

0 Upvotes