I want to create a code snippet from an automation studio script activity. Implementation works perfect in a landing page. But during the automation execution I got an error:

{"Status":"Error","RequestID":"7550d17a-53b0-4e50-bc2b-16e8dfda01bc","Results":[{"NewID":0,"NewObjectID":null,"PartnerKey":null,"Object":null,"CreateResults":null,"ParentPropertyName":null,"StatusCode":"Error","StatusMessage":"Value cannot be null.\r\nParameter name: principal can not be nullSystem.ArgumentNullException: Value cannot be null.\r\nParameter name: principal can not be null\r\n at ExactTarget.Core.StackSettingCollection..ctor(IAccountContext principal, String category, CacheType cacheType)\r\n at ExactTarget.ContentManagement.Instrumentation.Instruments.StatsDInstrument.<.ctor>b__1()\r\n at System.Lazy1.CreateValue()\r\n at System.Lazy1.LazyInitValue()\r\n at ExactTarget.ContentManagement.Instrumentation.Instruments.StatsDInstrument.<>c__DisplayClass9.b__8(Int64 elapsedMilliseconds)\r\n at ExactTarget.ContentManagement.Services.Assets.AssetService.Insert(IAssetV2 item)\r\n at PartnerAPIImplementation.ContentManagement.AssetImpl.CreateSingle(CreateOptions options, APIObject apiObject)","OrdinalID":0,"ErrorCode":0,"RequestID":null,"ConversationID":null,"OverallStatusCode":null,"RequestType":"Synchronous","ResultType":null,"ResultDetailXML":null}]}

No clue how to fix that. Documentation is not very helpful in this case.

I've implemented the snippet creation in two different ways. First via the new WSProxy. Second via the Platform Function. Both implementations same result.


var prox = new Script.Util.WSProxy();

var snippet = {
    Name: name,
    CustomerKey: name,
    AssetType: {
        Id: 220,
        Name: "codesnippetblock"
    Content: "....",
    Category: {
        Id: category,
        Name: categoryName

var res = prox.createItem("Asset", snippet);

Platform Functions:

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

var nameIdReference = Platform.Function.CreateObject("NameIdReference");
Platform.Function.SetObjectProperty(nameIdReference, "Id", 220);
Platform.Function.SetObjectProperty(asset, "AssetType", nameIdReference);

var categoryNameIdReference = Platform.Function.CreateObject("CategoryNameIdReference");
Platform.Function.SetObjectProperty(categoryNameIdReference, "Id", 1234);
Platform.Function.SetObjectProperty(asset, "Category", categoryNameIdReference);

var content = "code snippet code";

Platform.Function.SetObjectProperty(asset, "Name", "SSJS Code Snippet Block");
Platform.Function.SetObjectProperty(asset, "Content", content);

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

I have completely no idea what is missing or wrong here

1 Answer 1


Solved my problem in using REST API. It seems, that SOAP does not support the creation of Content Builder Assets.

var url = 'https://auth.exacttargetapis.com/v1/requestToken';
var contentType = 'application/json';
var payload = '{"clientId":"' + clientId + '",';
payload += '"clientSecret":"' + clientSecret + '"}';

var accessTokenResult = HTTP.Post(url, contentType, payload);
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).accessToken;

url = "https://www.exacttargetapis.com/asset/v1/content/assets";
var headerNames = ["Authorization"];
var headerValues = ["Bearer " + accessToken];

payload = "{";
payload += ' "category": {';
payload += '  "id": 1234,';
payload += '  "name": "code snippets"';
payload += " },";
payload += ' "assetType": {';
payload += '  "id": 220,';
payload += '  "name": "codesnippetblock"';
payload += " },";
payload += ' "content": "code-snippet code",';
payload += ' "description": "description for code-snippet",';
payload += ' "name": "name of code-snippet"';
payload += "}";

var result = HTTP.Post(url, contentType, payload, headerNames, headerValues);
var statusCode = result["StatusCode"];
var response = result["Response"][0];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.