0

I am trying to create content block in content builder using ssjs code but I am getting error, please check below code and how to resolve the issue?

    <script runat="server">
    Platform.Load("Core","1");

try {
Write("start</br>");

var asset = Platform.Function.CreateObject("Asset");
var nameIdReference = Platform.Function.CreateObject("NameIdReference");
Platform.Function.SetObjectProperty(nameIdReference, "Id", 197); //html block type
Platform.Function.SetObjectProperty(asset, "AssetType", nameIdReference);
var categoryNameIdReference = Platform.Function.CreateObject("CategoryNameIdReference");
Platform.Function.SetObjectProperty(categoryNameIdReference, "Id", 69208); 
Platform.Function.SetObjectProperty(asset, "Category", categoryNameIdReference);


Platform.Function.SetObjectProperty(asset, "Name", "SSJS HTML Content Block");
Platform.Function.SetObjectProperty(asset, "Content", "<div>my new content</div>");
Platform.Function.SetObjectProperty(asset, "ContentType", "text/html");

var statusAndRequest = [0,0];
var response = Platform.Function.InvokeCreate(NameIdReference, statusAndRequest, null);

Write(response.toString() + "</br>");
Write(statusAndRequest.toString() + "</br>");
Write("end</br>");

} catch (err) {
Write(Stringify(err) + "</br>");
}
</script>
1
  • what is the error you are getting? Commented Jul 26, 2018 at 13:27

1 Answer 1

0

The code below has worked.

<script runat="server">
Platform.Load("Core","1");

try {
Write("start</br>");


  var asset = Platform.Function.CreateObject("Asset");

//Set AssetType (complex property)
var nameIdReference = Platform.Function.CreateObject("nameIdReference");
Platform.Function.SetObjectProperty(nameIdReference, "Id", 197); //html block type
Platform.Function.SetObjectProperty(asset, "AssetType", nameIdReference);

//Set Category (complex property) - aka Folder
var categoryNameIdReference = Platform.Function.CreateObject("categoryNameIdReference");
Platform.Function.SetObjectProperty(categoryNameIdReference, "Id", 69208); //Use the Id value of the desired category (folder)
Platform.Function.SetObjectProperty(asset, "Category", categoryNameIdReference);

//Set Name, Content, and ContentType (simple text properties)
Platform.Function.SetObjectProperty(asset, "Name", "SSJS HTML Content Block");
Platform.Function.SetObjectProperty(asset, "Content", "<div>my new content</div>");
Platform.Function.SetObjectProperty(asset, "ContentType", "text/html");


var statusAndRequest = [0,0];
var response = Platform.Function.InvokeCreate(asset, statusAndRequest, null);

Write(response.toString() + "</br>");
Write(statusAndRequest.toString() + "</br>");
Write("end</br>");

} catch (err) {
Write(Stringify(err) + "</br>");
}
</script>

For detailed information: http://emailpeer.com/creating-content-blocks-through-ssjs-in-marketing-cloud/

4
  • Do you know how this would work for pictures? where would you insert the data of the picture? Or the http get call if you have an url of a picture you want to grab Commented Aug 1, 2018 at 12:04
  • I am not sure Johannes and I think the best way of finding this out is asking this question as a new question to reach others. Maybe someone would help you out :) Commented Aug 1, 2018 at 12:08
  • i used same code in my landing page but i am getting error please Check below error
    – MC_Cloud
    Commented Aug 30, 2018 at 6:33
  • start Error Value cannot be null. Parameter name: principal can not be nullSystem.ArgumentNullException: Value cannot be null. Parameter name: principal can not be null at ExactTarget.Core.StackSettingCollection..ctor(IAccountContext principal, String category, CacheType cacheType) at ExactTarget.ContentManagement.Instrumentation.Instruments.StatsDInstrument.<.ctor>b__1() at System.Lazy1.CreateValue() at System.Lazy1.LazyInitValue() at System.Lazy`1.get_Value() at PartnerAPIImplementation.ContentManagement.AssetImpl.CreateSingle(CreateOptions options, APIObject apiObject),0 end
    – MC_Cloud
    Commented Aug 30, 2018 at 6:34

You must log in to answer this question.

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