I am trying to send data with SSJS to an API but am not finding the error. I always receive the 500 error when publishing the cloudpage to test it.
<script runat="server">
Platform.Load("Core", "1.1.1");
// Define the URL
var url = "https://domain.de/be/api/v2/apply/referral/";
// Define the JSON payload
var payload = {
"tenant_id": 109,
"email": "[email protected]",
"first_name": "Name",
"last_name": "Name",
"zipcode": "35334",
"phone": "453-261-3853"
};
// Convert the payload to JSON format
var jsonPayload = Platform.Function.Stringify(payload);
// Define the Bearer token
var bearerToken = "sxsxs.scsddscsdcsdcsdcsd";
// Set the headers with the Bearer authorization
var headers = {
"Authorization": "Bearer " + bearerToken,
"Content-Type": "application/json"
};
// Send the HTTP POST request with the headers
var response = HTTP.Post(url, null, jsonPayload, headers);
// Check the response status
if (response.StatusCode == 201) {
Write("JSON sent successfully!");
} else {
Write("Failed to send JSON. Status code: " + response.StatusCode);
}
</script>