APIs & Integrations

WGreene
Member

Substituting Custom Properties into an Email Template via Marketing API

I use this technique with the Single Send API - I have a "template" (which is actually an Email) with some custom tags such as {{custom.messageBody}}. When I call the Single Send API I can pass dynamic (e.g. generated on our side and then sent via the API call) values that are sustituted into the message. The Marketing Email API also makes use of templates (though actual templates, not existing Emails), but I'm not clear if there is any way to pass dynamic content when I create the email. It seems strange that the Market Email API let's you pass some dynamic plaintext, but I don't see any mention oif our to pass HTML content when creating the email. Any help on this? 

Ideally, I would like to make a call like this...but somehow passing dynamic content.

 

 

    response = requests.request(
        "POST", 
        "https://api.hubapi.com/marketing/v3/emails/", 
        json={
            "subject": "Test Email from Template",
            "publishDate": "2024-03-22T20:56:13.512Z",
            "language": "en",
            "content": {
                "plainTextVersion": "Some plaintext generated on our end.",
                "templatePath": "EMAIL_DND_TEMPLATE/Test Template.html",
                # I want to pass dynamic data in somehow here -->  "customProperties": {"custom.messageBody": "<p>Some message body generated on our end.</p>"}
            },
            "name": "Test Email from Template",
            "campaign": "Test Campaign",
            "from": {"customReplyTo": "string", "fromName": "string", "replyTo": "string"},
            "state": "DRAFT",
            "to": {
                "contactLists": {"include": ["123"]},
            },
            "sendOnPublish": False,
        }, 
        headers={
            "accept": "application/json",
            "content-type": "application/json",
            "authorization": f"Bearer TOKEN",
        }
    )

 

 


I'm worried that perhaps the only way to do this is for the template itself to be the content and I really need to create a new template (with the dynamically generated content) via the API for every email I wish to create va the API...which doesn't seem right to me.

0 Upvotes
3 Replies 3
WGreene
Member

Substituting Custom Properties into an Email Template via Marketing API

I already use the sengle send API to send TRANSACTIONAL emails to individual contacts. Are you suggesting I can send MARKETING emails to Constact Lists using the single send API?

0 Upvotes
RyanneH
HubSpot Moderator
HubSpot Moderator

Substituting Custom Properties into an Email Template via Marketing API

Hey @Shane_Janssens , any potential insight you can share into this inquiry? This customer also opened a Support ticket about the features available within the new marketing email beta

0 Upvotes
Jaycee_Lewis
Community Manager
Community Manager

Substituting Custom Properties into an Email Template via Marketing API

Hi, @WGreene 👋 Welcome to our community. Thanks for your question. Have you looked into the Marketing Single Send API? It's out of beta now. 

 

Best,

Jaycee





loop


Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.

Learn More




0 Upvotes