0

Hi Marketing Cloud gurus,

Does anyone know how to create a text-only email programmatically? I am building an application in a Cloudpage (so users don't have to login into SFMC and the initial step is a "setup" process that:

  1. creates a Data Extension
  2. creates a personalised text-only email (very simple, only 2 sentences)
  3. creates the associated Triggered Send definition.

I am ok with 1 and 3, but I have no idea how to do 2.

Thank you

2 Answers 2

1

are you familiar with Content Builder API?

https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/content-api.html

textonlyemail is asset type 209:

https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/base-asset-types.html

... and here is a piece of sample code for the full call (actually - here is an entire library of samples: https://www.postman.com/salesforce-developers/workspace/salesforce-developers/request/14448118-f6c3c300-c990-4943-8cfc-15a622c2b34e )

==

If you have that, all you need to do is get an access token and send that via a HTTP POST from your SSJS.

Here is a good example of an http POST request in SSJS: SSJS HTTP.Post throws error instead of returning status code

Full request:

From the linked example, towards the bottom I changed "htmlemail" to "textonlyemail" and 208 to 209.

Then I removed the html content, inserted text content.

POST https://{{subdomain}}.rest.marketingcloudapis.com/asset/v1/content/assets
{
    "name": "Postman Demo - txt Email",
    "channels": {
        "email": true,
        "web": false
    },
    "views": {
        "html": {
        },
        "text": {
            "content": "text"
        },
        "subjectline": {
            "content": "%%First_Name%% this is my subject line"
        },
        "preheader": {
            "content": "and this is my preheader"
        }
    },
    "assetType": {
        "name": "textonlyemail",
        "id": 209
    }
}

Result:

enter image description here

And the content:

enter image description here

2
  • Thanks Jonas - That's awesome and I really like this approach. I would have liked to avoid using the REST API, because it means that the users need to enter some credentials for the authentication and then the asset creation. From the top of your head, there is no other alternative?
    – nerran
    Commented May 25, 2022 at 7:20
  • I believe your cloudpage should be authenticated no matter what, unless you want a basically public UI ("no one knows the URL" is the only security) to manipulate your Marketing Cloud. This is also the case when you create a DE etc. using WSProxy and not a new problem introduced with using REST. not sure if I understand the question, but the API integration would likely be server to server, i.e. the user shouldn't be required to enter the token/ clientId / clientsecret each time but the credentials would be available to the app and it "authenticates itself" when performing the action. Commented May 25, 2022 at 7:49
0

Finally found out that it's possible to use WS proxy. However, the email will get created into Classic Content

https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/email.html

var prox = new Script.Util.WSProxy();
var configEmail = {
    "CustomerKey": String(Platform.Function.GUID()).toUpperCase(),
    "Name": "txtemail_prox",
    "Subject": "Email created with wsproxy",
    "TextBody": "Hi %%firstname%%, this is the text email",
    "EmailType": "Text Only",
    "IsHTMLPaste": true
}

try {
    var email = prox.createItem("Email", configEmail);
    Write('Response' + Stringify(email));
} catch (error) {
    Write('Message' + error)
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .