wix-marketing-backend > coupons > createCoupon() not working

The code examples here https://www.wix.com/corvid/reference/wix-marketing-backend.coupons.html#createCoupon didn’t work for me.

Returns “No coupon type”, no coupon gets created.

Anyone suggestions on this?

This is my code:

backend

// Filename: backend/test.jsw (web modules need to have a .jsw extension)
import wixMarketing from 'wix-marketing-backend';

export function createCoupon() {
 let couponData = {
 "name": "My Coupon",
 "code": "myCouponCode",
 "startTime": new Date(),
 "expirationTime": new Date(2020,12,31),
 "active": true,
 "scope": {
 "namespace": "stores"
    },
 "moneyOff": 10,
  };
 
 return wixMarketing.createCoupon(couponData);
}

page

import { createCoupon } from 'backend/test';

$w.onReady(function () {
    createCoupon().then(id => {
            console.log(id);
        })
        .catch(err => {
            console.log(err);
        });
}

After the useless answers from support@wix.com I played around with the code, now it works. Instead of using “moneyOff” I used “moneyOffAmount”. Hopefully might help someone out there facing the same issue.

// Filename: backend/coupon.jsw (web modules need to have a .jsw extension)

import wixMarketing from ‘wix-marketing-backend’;

export function myCreateCoupon(name) {
let couponData = {
name: name,
code: ‘myCouponCode’,
startTime: new Date(),
expirationTime: new Date(2020, 12, 31),
active: true ,
scope: {
namespace: ‘stores’,
},
moneyOffAmount: 10,
};

return wixMarketing.createCoupon(couponData);
}

Not to be weird, but… I freaking love you. After hours and hours of trying to figure out how to create a coupon, your simple solution fixed everything.

Do you know how I could make it a percentOff coupon?
percentOff and percentOffAmount don’t work.

Thanks

Glad I could help you with this. I was lucky and figured it out by guessing. I did not have to use percentOff, but maybe try percentOffNumber or percentOffPercent. The idea of using amount came to me due to the tooltip that appears when creating a coupon in the frontend, maybe you get an idea when you check there for percentOff coupon type. Good luck!

See the wix-marketing-backend CouponInfo API for more information. You’ll find a complete list of properties that can be used in CouponInfo .

The problem is that the documentation is wrong. It says to use
“percentOff”
“moneyOff”
“fixedPrice”

but none of them work. Somehow “info” figured out that moneyOffAmount works, which is nowhere to be found in documentation.

Nice catch guys. Thanks for pointing this out. I sent this on to the docs team to sort this out.

Thank you! I appreciate the help

Thanks for finally paying attention to this. support@wix.com is lost when it comes to Corvid issues.

Thanks again everyone. The docs are now fixed. :beers:

Thank you so much Yisrael! It works perfectly now. Can’t believe I didn’t guess “percentOffRate” haha.

You shouldn’t have to guess - that’s what docs are for. But then again, we’re developers - we don’t need no steenking docs.

Hi! I am not a developer and am only using the wix editor platform to create coupon codes. I am still getting the “Coupon Unavailable” flag, can someone help me?

Please add your own issue into a new post instead of bumping up an old post. Explain what you are trying to do, what works, and what doesn’t. Also, add any code in a code block as stated in the Forum Guidelines.

This forum is dedicated to Corvid. If you are not using code, you should contact Wix Customer Care . They will be better able to assist.

This post is an old post and is being closed.