Marketing Cloud SSJS and send a request to the API(User, and Pass with BASE64)

103 views Asked by At

I want to authenticate Get, User, and Pass with BASE64 using Marketing Cloud SSJS and send a request to the API.

I wrote the program below and tried calling the API, but the results of the API request are not returned. If you make the same request using POSTMAN, the result will be returned. I think the endpoint, username, and password are correct. For BASE64 conversion, I referred to the following URL. https://salesforce.stackexchange.com/questions/286514/how-do-i-send-an-http-post-api-call-through-a-script-activity-using-basic-auth

If you could teach me, it'll help a lot.

<script runat="server">

Platform.Load("Core", "1.1.1");

var apiEndpoint = "https://xxxxxxxx";
var username = "username";
var password = "password";
  
function base64Encode(str) {
  var base64 = Platform.Function.Base64Encode(str);
  return base64;
}

var request = new Script.Util.HttpRequest(apiEndpoint);

var authHeader = "Basic " + base64Encode(username + ":" + password);
request.setHeader("Authorization", authHeader);

request.method = "GET";

try {
  var response = request.send();

  Write("Response Code: " + response.statusCode);
  Write("Response Content: " + response.content);

} catch (ex) {
  Write("Error: " + ex);
}

</script>
0

There are 0 answers