0

I am trying to find a way to create an email with a click from the browser using Javascript client side & server side ( AJAX ), but now having issues with SSJS, I tried to retrieve the id of the folder I want to create the email in but now success..

The script I am using is from the documentation, as I said the only thing I changed is the category id ( put the folder id, I suppose its right )

<script runat=server>
Platform.Load("core", "1");
try {
  var newMail = {
    CustomerKey : "test_email_key",
    Name : "Test Taoufiq Email",
    CategoryID : "269685",
    HTMLBody : "<b>This is a test email</b>",
    TextBody : "This is a test email",
    Subject : "Test Email Subject",
    IsActive : "true",
    IsHTMLPaste : "true",
    Status : "active",
    EmailType : "HTML",
    CharacterSet : "US-ASCII",
    HasDynamicSubjectLine : "false"
};
  
var myEmail = Email.Add(newMail);

} catch (ex) {
        Write("An error has occurred: " + Stringify(ex));
        Variable.SetValue("@Result", Stringify(ex));  //sets above ampscript variable
    }
  
</script>

The error I am getting is a general one : Error Adding Email nothing more

Anyone have an idea and got the chance to work on this before ?

Any help would be much appreciated.

1 Answer 1

1

The Email functions are actually connected to the Classic Emails from Email Studio, not Content Builder - making these functions pretty much unusable now that Classic has been sunset. These functions as well as WSProxy are attached to the SOAP Objects and the only way to access Content Builder is via the REST API.

This is likely why you are receiving that error and why this is not working.

3
  • there was an error, Actually I did not specify the ctegory id and it worked but this isn't useful anyways, content is being created successfuly because I don't get any error ( when I reexecute scriot, I get error because of duplicated name ), but it is in the CLASSIC content that isn't accessible now anyways .. But I can't create an email message using the REST API, from what I have seen, so does that mean there is no solution ?
    – TaouBen
    Mar 3, 2022 at 2:04
  • yes, it is possible to create content via REST API
    – TaouBen
    Mar 3, 2022 at 9:21
  • 1
    If its just the email, yes you can use the POST asset/v1/content/assets endpoint. If you mean you want to send an email, you can use the undocumented POST messaging/v1/rest group of endpoints to find the one that best suits your needs. Mar 3, 2022 at 14:35

You must log in to answer this question.

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