I am trying to create an html email, which is already stored in a field of one of my Data extension. The email is retrieved correctly and even i am able to print it in cloud page, but i am getting bad request error on creating the asset in sfmc. I am able to create the email with single line of code like "h2 Test Email /h2--", but when its the whole html content, code is breaking. My code is given below,
"<script runat="server">
Platform.Load("core", "1");
var myDE = DataExtension.Init("external key");
var filter = {Property:"Contact Key",SimpleOperator:"equals",Value:"5424"};
var data = myDE.Rows.Retrieve(filter);
for(var i=0; i< data.length; i++)
{
if(csv in data[i])
{
var html = data[i]["csv"];
}
}
if(html)
{
var restInstanceUrl = "https://subdomain.rest.marketingcloudapis.com/",
accessToken = "";
try {
var payload = {
name: "My HTML Email",
channels: {
email: true,
web: false
},
views: {
html: {
content: html
},
text: {},
subjectline: {
content: "Hello, this is my subject line"
},
preheader: {
content: "and this is my preheader"
}
},
assetType: {
name: "htmlemail",
id: 208
},
category: {id: "398609" },
contentType:"text/html"
};
var endpoint = restInstanceUrl + "asset/v1/content/assets";
var request = new Script.Util.HttpRequest(endpoint);
request.emptyContentHandling = 0;
request.retries = 2;
request.continueOnError = true;
request.setHeader("Authorization", "Bearer " + accessToken);
request.method = "POST";
request.contentType = "application/json";
request.postData = Stringify(payload);
var results = request.send();
var result = Platform.Function.ParseJSON(String(results.content));
Write("success");
} catch(error) {
Write("failed");
}
}
</script>"
Could you suggest any possible solutions?
Thanks