I'm leveraging SSJS WSProxy's HTTP Request to send a payload over to a third-party server. The payload is essentially a data extension's information that is being looped over until all records are sent over the third-party server.
I don't think the issue is the payload because if I keep refreshing this script, it will eventually be able to complete the entire list of records that need to be injected.
The issue is that it's almost as if I'm limited- sometimes the script will run 50 records at once, most times it only runs 10 records until erroring out. It's a random number of records everytime. This can be a pain as when I have 3000 records, having to refresh until the entirety of that data extension is passed over the third-party takes an hour of manual refresh.
I've tried splitting my data extensions down to small lists of 50 and I still face the same issue.
Please note that the access token is retrieved in a separate step and stored in a data extension to avoid having to retrieve it multiple times
Is there a better way that I can be debug this? I'm not really getting back a meaningful error message right now.
Here is my code - altered a few things to protect sensitive data.
<script runat="server" type="text/javascript">
Platform.Load("core", "1.1.5");
var SessionID = DataExtension.Init("external key here");
var Points = DataExtension.Init("external key here");
var data = SessionID.Rows.Retrieve();
var dataDE = data.length -1;
var datas = data[dataDE];
var accessToken = datas.Codefrom;
var filter = {
LeftOperand:{
Property:"Status",
SimpleOperator:"notEquals",
Value: "1"
},
LogicalOperator:"OR",
RightOperand:{
Property:"Status",
SimpleOperator:"isNull"
}
};
var pointsdata = Points.Rows.Retrieve(filter);
try{
for (var i=0; i < pointsdata.length; i++)
{
var pointdata = pointsdata[i];
var card_number = pointdata.card_number;
var transaction_id = pointdata.transaction_id;
var point_value = pointdata.point_value
//PROD
var url = 'endpoint URL here';
//PROD
var payload={
"PointValue":point_value,
"ProgramGuid":"a2fe52ae-0000-0000-0000-000000000",
"Reward":1,
"CardNumber":card_number,
"SessionGuid":accessToken,
"TransactionMetadataDescription":"Offer"
};
var req = new Script.Util.HttpRequest(url);
req.emptyContentHandling = 0;
req.retries = 2;
req.continueOnError = true;
req.contentType = "application/json"
req.method = "POST";
req.postData = Stringify(payload);
var resp = req.send();
var resultJSON = Platform.Function.ParseJSON(String(resp.content));
var message=resultJSON.Result.Message;
var messageDetails=resultJSON.Result.MessageDetails;
var status=resultJSON.Result.Status;
var brokertransactionId=resultJSON.BrokerTransactionId;
Write(status+"<br>");
Write(Stringify(resultJSON)+"<br>");
var upsert = Platform.Function.UpsertDE("de_to_log_status_to",["card_number","transaction_id"],[card_number,transaction_id],["Message","Status","MessageDetails","BrokerTransactionId"],[message,status,messagedetails,brokertransactionId]);
};
} catch(error) {
Write(Stringify(error))
};
</script>