Wix marketing backend create coupon() Minimum Subtotal Parameter issue

Hi, I realize this is a very random and specific problem, but it seems like “MinimumSubtotal” is not the correct parameter for the createCoupon function. I can’t find anything on this topic, so I’m hoping someone can help before our next farming season starts and customers start needing to create coupons! (lol, like next week;)

Here’s my backend module.


import wixData from 'wix-data';
import { coupons } from 'wix-marketing-backend';

export async function createMyCouponModule(VARIABLE) {
  wixData.query("CouponCodes")
      .eq("_id",VARIABLE)
      .find()
      .then((results) => {
        let code = results.items[0].code;
        let name = results.items[0].customer;
        let amount = results.items[0].amount;
        let expirationDate = new Date();
            expirationDate.setMonth(expirationDate.getMonth() + 12);
        let minimumSubtotal = 2;
       console.log(name);
      console.log(code);
      console.log(amount);

  let couponInfo = {
    "name": name,
    "code": code,
    "startTime": new Date(),
    "expirationTime": expirationDate,
    "active": true,
    "minimumSubtotal": minimumSubtotal,
    "scope": {
      "namespace": "stores"
    },
    "moneyOffAmount": amount // defined in frontend code
  };
      
  return coupons.createCoupon(couponInfo);
  
});
}

Everything else like name, code, startTime, expirationTime, and MoneyOffAmount is working fine. I’ve checked the “Marketing/Coupons” DB and the Minimum Subtotal field name is the same (and is set to number.) …any ideas? We’ll send you some fresh veggies from our farm! :carrot::corn::cucumber:

https://www.wix.com/velo/forum/coding-with-velo/wix-marketing-backend-coupons-createcoupon-not-working

Hi @nicolecentgraf ,

Your code looks correct.

You can try to create a coupon in the original interface provided in the Wix dashboard, then query the coupon with API, see if the coupon object structure is different from yours.

Certified Code

Good, glad to have another pair of eyes look at my code! Manually creating hundreds of coupons is unworkable, which is why I coded it to create coupons upon customer registration.

Honestly, I could skip the Minimum Subtotal thingie, but two years ago there was a bug that I experienced with coupons. The work around was to always add a Minimum Subtotal (which is why I have it set to $2, as that’s the cheapest item in my store;)

I mean, there’s a chance that they’ve since resolved that issue, but that sounds risky to me:p

How do we even report this issue? I know calling the wix help number will just lead to them telling me this is a velo issue.

Thanks for responding!

Hi Nicole,
We have a team who investigates Velo issues, and then passes bugs along to our developers to fix. If the code example in the API reference needs to be updated, they will handle it. Please report bugs following the process described here: https://www.wix.com/velo/forum/coding-with-velo/how-to-report-a-bug-1
Thanks!

@marlowe-shaeffer Cool, I will do that! Thanks for the help:)

Randomly came across the solution: https://www.wix.com/velo/forum/coding-with-velo/i-think-there-is-a-problem-with-coupons-api

It was buried in a wrongly dependent clause regarding “free shipping” coupons in the API. Apparently, you need to either define the scope or the minimum subtotal–no matter which coupon type. You cannot define both.

It’s working great now:)