Set preview text and style settings when creating HubSpot marketing email

SOLVE
New Contributor

(This is cross-posted from Stack Overflow)

 

I'm trying to create a marketing email through the HubSpot API. I have a subject, preview text, HTML body, and a CSS style sheet I want to apply to the body.

The subject and the body are easy, but the docs aren't very clear about how to include the preview text and style sheet, or even whether it's possible. No mention of either is made on the page for the create marketing email endpoint, so I'm looking at the example for GETting the details of an email, and assuming that the format corresponds.

The preview text appears to be shown inside a "widget", whatever that means:

  "widgets": {
    "preview_text": {
      "body": {
        "value": ""
      },
      "child_css": {},
      "css": {},
      "id": "preview_text",
      "label": "Preview Text This will be used as the preview text that displays in some email clients",
      "name": "preview_text",
      "order": 0,
      "smart_type": null,
      "type": "text"
    }
  }

But when I tried providing it in that format in the create POST, the text didn't show up in HubSpot as I expected it to. (I also tried setting the preview text myself in HubSpot and fetching the details through the API, and it looked just like the example above, except that the smart_type property wasn't there. Uploading without that property doesn't help.)

Style sheet information looks like it should be easy; there's a styleSettings property in the GET response, and a comment on the Marketing Email Overview page describes it as "String; Custom email style settings (background color, primary font)". So I tried just including the styles as I would format them in a CSS file. The POST returned an error response, without much useful info that I could see.

I found a workaround for the CSS issue; if I upload the email body as a full HTML document, rather than just the HTML body, then the styles appear to be used in previews of the email on HubSpot (though not when editing; I guess that makes some sense).

So really the preview text is my main priority, but if anyone knows how to do either, I'd really like to know.

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Highlighted
HubSpot Moderator

Hi @aldel,

 

I've been testing this functionality today. I can create an email with preview text included if I include that format in the body of the POST request. So here's an example payload where I included preview text in a newly created email:

 

{
  "name": "API POST testing email",
  "subject": "Sample subject line",
  "widgets": {
    "preview_text": {
      "body": {
        "value": "Some preview text"
      }
    }
  },
  "templatePath": "Archive/Custom/email/responsive_email/1 Column Above Body.html"
}

If that's not helpful, could you paste what the body of your request was? Or at least, one example that wasn't working? I'll be happy to take a look at what's going on there. And as for adding CSS into your email, could you add an HTML module onto the template, and then insert your CSS into that module? You'd probably want to pull the email from the API, see what the module's internal name is, and then pass your CSS into the html field, which will be inside the the body field of that module. I'm happy to provide an example for this also if you think it will help clarify it.

 

Leland Scanlan

HubSpot Developer Support
2 Replies 2
Highlighted
HubSpot Moderator

Hi @aldel,

 

I've been testing this functionality today. I can create an email with preview text included if I include that format in the body of the POST request. So here's an example payload where I included preview text in a newly created email:

 

{
  "name": "API POST testing email",
  "subject": "Sample subject line",
  "widgets": {
    "preview_text": {
      "body": {
        "value": "Some preview text"
      }
    }
  },
  "templatePath": "Archive/Custom/email/responsive_email/1 Column Above Body.html"
}

If that's not helpful, could you paste what the body of your request was? Or at least, one example that wasn't working? I'll be happy to take a look at what's going on there. And as for adding CSS into your email, could you add an HTML module onto the template, and then insert your CSS into that module? You'd probably want to pull the email from the API, see what the module's internal name is, and then pass your CSS into the html field, which will be inside the the body field of that module. I'm happy to provide an example for this also if you think it will help clarify it.

 

Leland Scanlan

HubSpot Developer Support
New Contributor

Great, thanks! I think it's working (haven't had a chance to really test yet). This makes more sense than what I saw in the documentation.

Reply
0 Upvotes