0

I am trying to pull a JSON payload that exists as a value in a field in a data extension into an API call. When I try this I am getting a 422 response. I have tried writing the value of the DE field and this works. Then when copy and pasting the result and hardcoding it into the API call this also works.

This is the SSJS I am using

<script runat="server">
Platform.Load("Core","1.1.1");

var dataExtensionName = "C1 Enquiry ML test";
var fieldName = "c1";
  
var  birthdayDE = DataExtension.Init("C1 Enquiry ML test");
var data = birthdayDE.Rows.Retrieve(); 
var payload = data[0].c1;

Write("C1: " + payload);

var authURL = "https://endpoint";
var authPayload = {
    "data": payload
};
var req = new Script.Util.HttpRequest(authURL);
req.emptyContentHandling = 0;
req.retries = 1;
req.continueOnError = true;
req.contentType = "application/json";
req.setHeader("Ocp-Apim-Subscription-Key", "KEY");
req.method = "POST";
req.postData = Platform.Function.Stringify(authPayload);
var resp = req.send();
var respObj = Platform.Function.ParseJSON(String(resp.content));
var leadScores = respObj.lead_scores;
if (leadScores && leadScores.length > 0) {
    var leadScore = leadScores[0].lead_score;
    Write("Lead Score: " + leadScore);
} else {
    Write("No lead scores found in the response.");
}
Write("Response Status: " + resp.statusCode);
</script>

0

You must log in to answer this question.

Browse other questions tagged .