Hubspot API - Create Marketing Email

I am trying to use an AI assistant to create a Marketing Email draft in HubSpot via API.

The API successfully creates the email draft and sets fields such as:

  • email name
  • subject line
  • preview text
  • draft state

However, I cannot make the main email body content appear in the HubSpot editor or preview.

What happens:

  • I send body HTML into content.widgets
  • API GET /marketing/v3/emails/{emailId} shows that the HTML content is saved
  • but in the HubSpot email editor and preview, the email body is still empty / not rendered

The email seems to use a Drag-and-Drop template. Could this be the reason?
Does HubSpot support inserting the main body content into a Drag-and-Drop Marketing Email via API?

If yes, could you please share the correct API payload structure for adding body content that is visible in the editor and preview?

If not, what is the recommended API-compatible template type or workflow for creating a Marketing Email draft with body content via API?

Thank you.

Hi @YS and welcome, we are so glad to have you on the HubSpot Community! :orange_heart:

Thanks for reaching out!

Yes, the Drag-and-Drop template type is actually why your body content isn’t showing up as expected.

The emailTemplateMode field on emails will return either DESIGN_MANAGER or DRAG_AND_DROP. With drag-and-drop emails, the layout is stored as structured JSON that’s managed by HubSpot. Here is the documentation: " Marketing API | Marketing Email - HubSpot docs ".

This means you can’t inject custom HTML into the body using content.widgets and have it display within the drag-and-drop editor. While the data is saved to the API, the editor handles its own internal layout, so it simply doesn’t render that content.

Now, I’d love to check with our Top Experts: Hi @Anton, @evaldas and @johnelmer can you think of a workaround to help @YS, please?

Thanks so much and have a lovely day!
Bérangère

This post was created with the assistance of AI tools

If you have an email that you designed with the look and feel of what you want, you can use the API to pull that which would give you the payload for the content.

The payload is listed under the “content” property for drag and drop emails and generally have two parts: sections and widgets. The sections define the sections (including columns) and the widgets are modules.

I haven’t tried it with AI but I don’t see why you couldn’t make an email template using placeholder data and then tell AI to replace the placeholder data with the content.

The payload is pretty long for a complete email so it’s a bit hard to post but here’s a sample of the content and widget code. Ids must match properly so I generally custom set the id values for the sections/columns/widgets to make it easier to navigate.

    "content": {
        "flexAreas": {
            "main": {
                "boxFirstElementIndex": 1,
                "boxLastElementIndex": 11,
                "boxed": true,
                "isSingleColumnFullWidth": false,
                "sections": [
                    {
                        "columns": [
                            {
                                "id": "column_header_1_1",
                                "widgets": [
                                    "module_header_1_1_1"
                                ],
                                "width": 12
                            }
                        ],
                        "id": "section_header_1",
                        "style": {
                            "backgroundType": "CONTENT",
                            "paddingBottom": "0px",
                            "paddingTop": "0px",
                            "stack": "LEFT_TO_RIGHT"
                        }
                    }
                ]
            }
        },

Widgets:

        "widgets": {
            "module_header_1_1_1": {
                "body": {
                    "css_class": "dnd-module",
                    "font": {
                        "color": "#000000",
                        "font": "Arial, sans-serif",
                        "size": {
                            "units": "px",
                            "value": 12
                        },
                        "styles": {
                            "bold": false,
                            "italic": false,
                            "underline": false
                        }
                    },
                    "hs_enable_module_padding": false,
                    "hs_wrapper_css": {},
                    "lineNumber": 49,
                    "module_id": 2794854,
                    "parent_widget_container": null,
                    "path": "@hubspot/email_web_version_link",
                    "schema_version": 2,
                    "startPosition": -176
                },
                "child_css": {},
                "css": {},
                "id": "module_header_1_1_1",
                "label": null,
                "module_id": 2794854,
                "name": "module_header_1_1_1",
                "order": 1,
                "smart_type": null,
                "styles": {
                    "breakpointStyles": {
                        "default": {
                            "hidden": false
                        },
                        "mobile": {
                            "hidden": false
                        }
                    }
                },
                "type": "module"
            }
        }

Hi, I hope you’re doing well.

The issue occurs because Drag-and-Drop email templates only render content within predefined widgets. If the content.widgets structure doesn’t exactly match the template’s widget hierarchy, the content may save successfully but won’t appear when the email is rendered.

Recommended Solution: Create a custom-coded email template with a dedicated content placeholder and then reference that template when creating the email.

1. Create template:
curl --location 'https://api.hubapi.com/designmanager/v1/templates’ \
–header ‘Content-Type: application/json’ \
–header ‘Authorization: Bearer {{YOUR_TOKEN}}’ \
–data ‘{
“category_id”: 2,
“is_available_for_new_content”: true,
“template_type”: 2,
“path”: “/custom-email-template”,
“source”: “<table width=\“100%\”><td align=\“center\”><table width=\“600\”>{{ contact.rich_text_block|raw }}”
}’

2. Create email using that template:

curl --location 'https://api.hubapi.com/marketing/v3/emails’ \
–header ‘Content-Type: application/json’ \
–header ‘Authorization: Bearer {{YOUR_TOKEN}}’ \
–data ‘{
“name”: “Sample Marketing Email”,
“subject”: “Sample subject line”,
“content”: {
“templatePath”: “/custom-email-template”
}
}’

Important: The value specified in the path field while creating the template must exactly match the templatePath used when creating the email.

This approach gives you full control over where the email body content is rendered and avoids relying on Drag-and-Drop widget mappings, which can be difficult to predict and maintain.

I hope this will help you out. Please mark it as Solution Accepted and upvote to help another Community member.

Thanks!