Hi, I am trying to send a custom payload to an email template but Hubl will not correctly parse the object so that I can map over the data.
I have tried sending my custom payload (languages) as a string and as an array but when I try to then render it on my template using `custom.LANGUAGES|fromjson` I get an error that it is an invalid input. See code below for POST request.
I can provide the sample email template if necessary. Thanks for any help!
payload = {
“emailId”: EMAIL_ID,
“message”: {
“to”: YOUR_EMAIL,
“from”: YOUR_EMAIL,
},
“customProperties”: {
“languages”: [{“name”:“English”},{“name”:“Spanish”},{“name”:“French”}]
},
}
email_response = requests.post(
“https://api.hubapi.com/marketing/v3/transactional/single-email/send”,
data=json.dumps(payload),
params={“hapikey”: HUBSPOT_API_KEY},
headers={“accept”: “application/json”, “content-type”: “application/json”},
)
Hi LeeBartelme, thank you so much! You are totally right. I ended up going with the solution where I just generate the HTML on our end and send it over to Hubspot as a string. Really appreciate your response.
@KTriviso do you happen to have a code example you can share? I’m trying to do this exact thing but am struggling with how to format the HTML and how to reference it properly in the programmable email module.
I was able to solve this issue my stringifying the HTML. Inside the HTML string, I reference the email fields like so -
dynamic_title = '<h2>Your order confirmation</h2>'
payload = {
emailId: ***,
message: {***},
customProperties: {
***,
dynamic_title: dynamic_title
}
}
Next, in your email template, open the HTML file. Find where you want the field above, and reference like this -
<div>
{{custom.dynamic_title}}
</div>
Then, send the above payload in your POST to see your dynamic title in your email.
Hope that helps!
Thank you, this was so incredibly helpful
Hey, @danielrlambert
Please consider accepting @KTriviso’s soluion if it worked for you.
Best,
Jaycee
Thank you very much for sharing this @KTriviso
— Jaycee
I encountered this problem while working for single email sends through Hubspot API.
I have no posibility of using the HubL language in the e-mail designer tool because customProperties are not correctly parsed. Any dynamic object I try to pass into a custom property ends up being read as a string, instead of an array or an object.
The solution below helps a lot for simple dynamic data, but when working with large dynamic and complex data objects and specific css being applied, we end up splitting the responsabilities for email management between the service making the email API call and Hubspot.
For example, for a table with dynamic data, I would have to design this dynamic table and its logic in the backend service that makes the API call so that I can inject a customProperty containing this html table as a string. This means that when a marketing agent needs to change the aspect of the e-mail, they would be able to change the email’s aspect in Hubspot but all the dynamic rendering that is sent through the API would need to be modified by a developper. This sunks code maintenability for our current service and we end up loosing all the advantages and independence that Hubspot has put into place for email design.
I would like to know if at any point this issue will be tackled by Hubspot ? For the moment I have not found any other option than injecting html as a string in custom properties.
Hi @EAVILA2 and welcome, we are so glad to have you here!
Thanks for reaching out to the HubSpot Community!
I also love to hear that the solution helps a bit, however I do understand that this is not the perfect solution for you, for large, dynamic and complex data.
I’d recommend that you submit the HubSpot Developer Feedback form so that the right Team can view your valuable feedback, thank you!
Also, let’s consult our Top Experts: Hi @sylvain_tirreau, @Anton and @zach_threadint do you happen to know of a workaround to help @EAVILA2, please?
Have a wonderful day and thanks so much for your help!
Bérangère