Skip to main content
added 1175 characters in body
Source Link
Adam Spriggs
  • 31.1k
  • 6
  • 44
  • 88

Looks like this:I think your payload structure is the issue.

req.postData = String(payload);

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

should beSomething like this will work:

req.postData = Stringify(payload);
<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>

Looks like this:

req.postData = String(payload);

should be:

req.postData = Stringify(payload);

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>
deleted 5 characters in body
Source Link
Adam Spriggs
  • 31.1k
  • 6
  • 44
  • 88

Looks like this:

req.postData = String(payload);

should be this:

req.postData = Stringify(payload);

Looks like this:

req.postData = String(payload);

should be this:

req.postData = Stringify(payload);

Looks like this:

req.postData = String(payload);

should be:

req.postData = Stringify(payload);
Source Link
Adam Spriggs
  • 31.1k
  • 6
  • 44
  • 88

Looks like this:

req.postData = String(payload);

should be this:

req.postData = Stringify(payload);