Trying to get the details for a coupon (SAMPLE$1OFF, created on Wix and visible in the Wix Coupons db) by using getCoupon() with the coupon _id as a parameter. Not sure where I’m going wrong, but the console results just show everything returned as “undefined”.
type or paste code here
Backend file GetCoupon.jsw
import { coupons } from 'wix-marketing.v2';
export async function getCoupon(id) {
try {
const result = await coupons.getCoupon(id);
return result;
} catch (error) {
console.log(error);
}
}
and the front-end call:
import {getCoupon} from 'backend/GetCoupon.jsw';
$w.onReady(function () {
let testCoupon = "1cc6a9bc-ed7b-4f8b-9650-93ffebc6340c" //SAMPLE$1OFF COUPON _id
getCoupon(testCoupon)
.then(results => {
let coupon = results
console.log("coupon name is:" + coupon.name);
console.log("coupon code is:" + coupon.code);
console.log("coupon money off amount is: " + coupon.moneyOffAmount);
console.log("coupon percent amount off is: " + coupon.percentOffRate);
})
.catch(error => {
console.log(error);
});
});