I built a code for auto generating a coupon code, everything works perfectly in preview, however I can’t see what is the problem on live. I don’t know why, but I always have problems on live VS preview
Hi Thanks for the answer !
Well, I can’t change the permissions on Coupons unfortunately, but I believe that running a query on this database isn’t suposed to be problematic, isn’t it ?
Thanks
Well, since it’s a WIX database I don’t have the option to sync it
Regarding the problem on Live :
The backend function works fine, creates a new coupon and duly returns its ID. The problem seems to occur later, upon the query : I don’t get any error message in the console (despite the .catch()) on Chrome but the function seems to stop anyway and return nothing. So, everything that is supposed to happen after the query is just not happening…
I actually have the same issue with another website and the permissions on databases are all duly set up.
I will put another ice cream in the freezer for you
Sometimes it takes time till my brain starts working…
OK, so now I understand. Your issue is that, as stated in the documentation , you can’t perform the query in the frontend since you need admin permissions:
When you run your site, since you are in the Editor, you are running as admin . However, when another user (not you) visits the site, that visitor doesn’t have the proper permissions. So, what you need to do is to perform the query in the backend and use the suppressAuth option.
Oh that’s pretty annoying… Is there any other way that I can give the newly created coupon to the user ? I mean, what’s the point of creating couons if we can’t display it ?
Umm, first of all, you can perform a query in the backend, and return the result to the frontend.
However, what I don’t understand is what are you missing from the coupon create ? The call to createCoupon() returns the couponInfo object which should have the information you want.
Oh I am so stupid… you are right ! I just have to return the values instead of returning the ID and run a query in order to get these values !
Really, why I didn’t even think of that… Thank you so much !
Man I have a crush on Guiness too ! However, I might be a bit far for a drink (I a in Tahiti, pacific islands). Will surely drink one for you ! Thanks again
I am not a coder and this code is just what I’ve been looking for. How do I actually trigger this? The only way I can think of is to create a temporary page with a button. Clicking the button then adds a coupon to the database. This works, but I need to create 1000 coupons. Is this possible, and how would I adapt the code to do that?