0

I am writing a script to retrieve data from one of our Data Extensions, and send it to an external API. Here is my script for this:

<script runat="server">
  Platform.Load("core", "1.1.5");
  var SMS_RBBB = "External ID for DE";
  var dataRows = DataExtension.Init(SMS_RBBB).Rows.Retrieve();
  var endpointUrl = "https://api.attentivemobile.com/v1/attributes/custom";
  var bearerToken = "My Bearer Token";
  for (var i = 0; i < dataRows.length; i++) {
    var payload = {
      properties: {
        zipcode: dataRows[i]["ZIP_CODE"]
      }
      ,
      user: {
        phone: dataRows[i]["MOBILE_PHONE"]
      }
    };
    try {
      var result = HTTP.Post(endpointUrl, "application/json", Stringify(payload), {
        "Authorization": "Bearer " + bearerToken}
                            );
      var jsonResponse = Platform.Function.ParseJSON(result.Response);
      Write(Stringify(jsonResponse));
    }
    catch (e) {
      Write("Error occurred: " + e.message);
    }
  }
</script>

When running this script, I receive the error: Error Message: Error occurred: Unable to retrieve security descriptor for this frame

This error is returned over and over for each record from the DE. Any input would be greatly appreciated.

Thanks,

Nick

1 Answer 1

0

The HTTP POST request should have 5 parameters. The last 2 ones are header names and header values.

I would try to change like this:

<script runat="server">
  Platform.Load("core", "1.1.5");
  var SMS_RBBB = "External ID for DE";
  var dataRows = DataExtension.Init(SMS_RBBB).Rows.Retrieve();
  var endpointUrl = "https://api.attentivemobile.com/v1/attributes/custom";
  var bearerToken = "My Bearer Token";
  var headerNames = ["Authorization"];
  var headerValues = ["Bearer " + bearerToken];

  for (var i = 0; i < dataRows.length; i++) {
    var payload = {
      properties: {
        zipcode: dataRows[i]["ZIP_CODE"]
      }
      ,
      user: {
        phone: dataRows[i]["MOBILE_PHONE"]
      }
    };
    try {
      var result = HTTP.Post(endpointUrl, "application/json", Stringify(payload), headerNames, headerValues);
      var jsonResponse = Platform.Function.ParseJSON(result.Response);
      Write(Stringify(jsonResponse));
    }
    catch (e) {
      Write("Error occurred: " + e.message);
    }
  }
</script>
2
  • Thank you Duc Le. I made the changes and when checking the Cloud Page, I'm seeing "We couldn't open this page. Try again later." The data extension has over 3,000 rows of data, could there be a limitation in how much data can be passed?
    – NHighton
    Commented Apr 12 at 16:48
  • @NHighton It seems there are 2 other issues you need to solve. One is the time-out error when you process the code on the Cloudpage and one is the data extension row retrieve function, which can only retrieve up to 2500 records. I would recommend you split your data source into smaller chunks and run the script in an Automation to increase the time processing.
    – Duc Le
    Commented Apr 13 at 1:11

You must log in to answer this question.

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