I am trying to do a PUT request. I am able to generate a token (using POST method) and am able to run this in POSTMAN and do a cURL command in the command line. I can't do it in SFMC though. I have tried the payload as JSON as well as this string in the code below. Any suggestions?
Here is my code:
Platform.Load("Core", "1.1.1");
try {
var authHeader = "Bearer xxxxxx";
var url = "https://eeeee.api.commercecloud.salesforce.com/pricing/coupons/v1/organizations/zxzxzxzxzxz/coupons/johnTestId1?siteId=TEST";
var contentType = "application/json";
var payload = "{\"couponId\":\"johnTestId1\",\"creationDate\":\"2024-07-25T04:56:35.929Z\",\"description\":\"Thiscouponisusedtogive10%offstuff.\",\"enabled\":false,\"exportedCodeCount\":0,\"lastModified\":\"2024-07-25T04:56:35.929Z\",\"redemptionCount\":3,\"redemptionLimits\":{\"limitPerCode\":1,\"limitPerCustomer\":1,\"limitPerTimeFrame\":{\"limit\":1,\"redemptionTimeFrame\":1}},\"systemCodesConfig\":{\"codePrefix\":\"TT\",\"numberOfCodes\":10},\"totalCodesCount\":10,\"type\":\"system_codes\"}";
var req = new Script.Util.HttpRequest(url);
req.method = "PUT";
req.contentType = contentType;
req.setHeader("Authorization", authHeader);
req.postData = String(payload);
var resp = req.send();
//Write("Response Status Code: " + resp.statusCode + "<br>");
//var payload = Platform.Function.ParseJSON(respContent);
//var accessToken = payload.access_token;
//Write(accessToken);
} catch (e) {
Write("Exception: " + e);
}
</script>
An error occurred when attempting to evaluate a Util.HttpRequest call. See inner exception for details. URL:https://eeeee.api.commercecloud.salesforce.com/pricing/coupons/v1/organizations/zxzxzxzxzxz/coupons/johnTestId1?siteId=TEST Method: PUT ClientID: 534002312 JobID: 0 ListID: 0 BatchID: 0 SubscriberID: 0
Error in HTTP request: Matching constructor not found for: Script.Util.HttpRequest