1

When attempting to make a HTTP POST Request in server side javascript I keep getting this error, not sure what the problem is but I cant seem to fix it.

 <script runat="server" language="javascript">

Platform.Load("Core","1");
try{

var url = '<endpoint>';
var contentType = 'application/json';
var payload = {
};


var headerNames = ["client_id", "client_secret"];
var headerValues = ["<client_id>", "<client_secret>"];

var accessTokenResult = HTTP.Post(url, contentType, payload, headerNames, headerValues);
var accessToken = Platform.Function.ParseJSON(accessTokenResult["Response"][0]).accessToken;

Write(accessToken.StatusCode + '<br>');
Write(accessToken.Response);
Write('Success');



  }
catch(e){
  Write("Error:" + e);
}
     </script>

1 Answer 1

1

Stringify the payload, to change your JS object to a JSON string.

var accessTokenResult = HTTP.Post(url, contentType, Stringify(payload), headerNames, headerValues);

I've found that error usually points to a function syntax error or incorrect function parameters.

You must log in to answer this question.

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