1

I am trying to retrieve a template-based email asset using the Content Builder API via a Cloud page. I am having trouble retrieving the template. I am not sure if it is an issue with the structure of the payload or a potential issue with the HTTP Get method. I am getting the following error message:

Unable to retrieve security descriptor for this frame.Failed to retrieve email template.

This is the code I have been using to make the request:

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

      var clientId = "{{REMOVED}}";
      var clientSecret = "{{REMOVED}}";
      var grantType = "{{REMOVED}}";
      var accountId = "{{REMOVED}}";

      try
      {
        var success = false;
        var accessToken = GetAccessTokenForAPI(clientId, clientSecret, grantType, accountId);
        if (accessToken != null)
        {
          success = retrieveEmailTemplate(accessToken);
        }
        if (success) {
          Write("Retrieved email template.");
        } else {
          Write("Failed to retrieve email template.");
        }
      }
      catch (exc)
      {
       Write("Exception Error: " + Stringify(exc));
    }

      function GetAccessTokenForAPI(clientId, clientSecret, grantType, accountId)
      {
       var url = 'https://{{REMOVED}}.auth.marketingcloudapis.com/v2/token';
          var contentType = 'application/json';
          var payload =
          {
            client_id: clientId,
            client_secret: clientSecret,
            grant_type: grantType,
            account_id: accountId
          };

          var accessTokenRequest = HTTP.Post(url, contentType, Stringify(payload));
          if (accessTokenRequest.StatusCode == 200) {
             var tokenResponse = Platform.Function.ParseJSON(accessTokenRequest.Response[0]);
             return tokenResponse.access_token;
          }
          else
          {
            return null;
            Write("Error");
          }
      }

      function retrieveEmailTemplate(accessToken)
      {

          var url = 'https://{{REMOVED}}.rest.marketingcloudapis.com/asset/v1/content/assets/query';

          var contentType = 'application/json';

         var headername = ["Authorization"];

         var headervalue = ["Bearer " + accessToken];

         var payload ='{"query":{"leftOperand":{"property":"name","simpleOperator":"equal","value":"{{REMOVED}}"},"logicalOperator":"AND","rightOperand":{"property":"assetType.name","simpleOperator":"equal","value":"templatebasedemail"}},"fields":["name","views","thumbnail","category","content","data"]}';
         try {
            var emailRequest = HTTP.Get(url, contentType, payload, headername, headervalue);
            var emailResult = Platform.Response.Write("Email request: " + emailRequest);
            return emailResult;
            }
        catch(err) {
            Platform.Response.Write("This is an error: " + err);
        }
      }
3

The simple query version is a GET, but you need to use POST for the Advanced Query version.

enter image description here

Using HTTP.POST instead will likely get you the expected results.

  • 1
    thank you for your response. I have swapped out it for a Post request now. I am getting the response now. I have also needed to add .Response to the variable emailResult. So it now looks like the following: ` var emailResult = Platform.Response.Write("Email request: " + emailRequest.Repsonse);`. Thanks. – Quaser8000 Sep 23 '19 at 12:38

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.