APIs & Integrations

DorL
Participant

Create marketing email via api issue

Hi,

I'm currently working on creating a marketing email using the following request:

 

POST /marketing-emails/v1/emails/

 

const body = {
name: 'Test marketing email',
subject: 'My email subject',
state: 'AUTOMATED_DRAFT',
emailBody: `Hi You {{contact.firstname}}`,
templatePath:  '@hubspot/email/dnd/welcome.html'
}
 

While the email is successfully created, I've encountered an issue where the email body remains the default template body instead of the custom body I included in the request.

 

Could you please advise on the necessary steps to resolve this issue?

 
0 Upvotes
4 Replies 4
zach_threadint
Guide

Create marketing email via api issue

Hi @DorL 👋

Just make sure you use 1 "Main Email Body" module in your email template. That should do the trick.

Screenshot 2024-01-20 at 11.14.12.png

 

I hope this proves useful. Please let me know if you have any follow-up questions.

All the best,

Zach

--

Zach Klein
HubSpot Integrations & App Developer
Meanjin / Brisbane, Australia



Say g'day


If my post helped answer your query, please consider marking it as a solution.


0 Upvotes
DorL
Participant

Create marketing email via api issue

I'd like to share my overall objective and see if you can assist me.

I want to create a sequence (or a workflow if sequence isn't possible) that, upon enrollment of a specific contact, triggers the automatic sending of a transactional email (or a marketing email if a transactional one isn't possible). The email should contain dynamic content, such as the contact name and a link that varies from one contact to another. 

 

I intend to achieve all of this exclusively through the API, involving the following steps:

  1. Creation of an email template
  2. Creation of the email itself
  3. Creation of the sequence or workflow

I appreciate your assistance!

0 Upvotes
zach_threadint
Guide

Create marketing email via api issue

Hi @DorL 👋

 

As per this (Legacy) HubSpot API doc, the "emailBody" parameter sets "the main content of the email within the 'main email body' module". As such, in your email template, you'll need to make sure you're using this "main email body" module. For example:

 

<!--
    templateType: email
    isAvailableForNewContent: true
-->
<!doctype html>
<html>

...

  <body>
    {% content_attribute "email_body" %}
      The content you send via API as "emailBody" should appear here.
    {% end_content_attribute %}

...

  </body>
</html>

 

 

More information about the "Main email body" can be found here.

 

I hope this proves useful. Please let me know if you have any follow-up questions.

All the best,

Zach

--

Zach Klein
HubSpot Integrations & App Developer
Meanjin / Brisbane, Australia



Say g'day


If my post helped answer your query, please consider marking it as a solution.


0 Upvotes
DorL
Participant

Create marketing email via api issue

Thank you @zach_threadint 

 

If I want to use a default drag-and-drop template, what should I do? (like welcome or simple templates)

0 Upvotes