0

I am updating the asset in SFMC using the below mentioned API / SSJS code :

var assetIdToUpdate = "115271"; // Replace with the actual asset ID you want to update
var assetHTML = rest_instance_url + "/asset/v1/content/assets/" + assetIdToUpdate; 

var headerNames = ["Authorization"];
var headerValues = ["Bearer " + accessToken];
var contentType = 'application/json'
var assetHTMLresponse = HTTP.Get(assetHTML, headerNames, headerValues);
var assetHTMLcode = assetHTMLfinalresponse.views.html.content;
var assetHTMLname = assetHTMLfinalresponse.name;
var assetHTMLdescription = assetHTMLfinalresponse.description;
var assetHTMLID = assetHTMLfinalresponse.assetType.id;

var payload = {
                name: assetHTMLname,
                description: assetHTMLdescription,
                channels: {
                    email: true,
                    web: false
                },
                assetType: {
                    name: "htmlemail",
                    id: assetHTMLID
                },
                views: {
                    html: {
                        content: assetHTMLcode
                    }
                }
            };

          
            var req = new Script.Util.HttpRequest(assetHTML);
            req.emptyContentHandling = 0;
            req.retries = 2;
            req.continueOnError = true;
            req.contentType = "application/json"
            req.setHeader("Authorization", headerValues);
            req.method = "PATCH"; // Use PATCH method for updating existing resources
            req.postData = String(payload);

            var resp = req.send();

            var resultJSON = Platform.Function.ParseJSON(String(resp.content));
            
          
            Write(Stringify(resultJSON)); 

However when I publish the cloud page I am getting the below mentioned error

{"message":"Unable to retrieve security descriptor for this frame.","description":"System.InvalidOperationException: Unable to retrieve security descriptor for this frame. - from mscorlib\r\n\r\n"}

Also I have attached the response when i stringify the payload I am assuming that the /n/n spacing problem could be one of the issue

2

1 Answer 1

0

I think your payload structure is the issue.

If you need to update other properties, retrieve a single asset using a GET on the same route -- and use that structure.

Something like this will work:

<script runat="server" language="JavaScript">

    Platform.Load("core", "1");

    var assetId = 766569
    var restbase = "https://mc-zzz.rest.marketingcloudapis.com"
    var url = restbase + '/asset/v1/content/assets/' + assetId;
    var authToken = ""

    var payload = {
        "content": "<!-- whoops2 -->"
    }

    Write("<br>url: " + url)        

    var req = new Script.Util.HttpRequest(url);
    req.emptyContentHandling = 0;
    req.retries = 2;
    req.continueOnError = true;
    req.contentType = "application/json"
    req.setHeader("Authorization", "Bearer " + authToken);
    req.method = "PATCH";
    req.postData = Stringify(payload);

    try {

        var resp = req.send();
        var resultStr = String(resp.content);
        Write("<br>resultStr: " + resultStr)        
        var resultJSON = Platform.Function.ParseJSON(resultStr);
        Write("<br>resultJSON: " + Stringify(resultJSON))

    } catch(e) {

        Write("<br>e: " + Stringify(e))

    }


</script>
7
  • Yes updated the same but still receiving the same error Commented Jan 29 at 9:09
  • Added an example that works. Commented Jan 29 at 14:41
  • I have added the screenshot of the string form of the payload as the image. Please let me know if this is something which can cause issue Commented Jan 29 at 15:40
  • You're going to have to make the new HTML content into an escaped string that's valid in JSON. That usually involves escaping double-quotes: " with \". Commented Jan 30 at 15:27
  • Can you help with the function that i need to use I tried replace but it still doesn't update the HTML Commented Jan 31 at 15:37

You must log in to answer this question.

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