# Undefined results when using getCoupon()

**URL:** <https://forum.wixstudio.com/t/undefined-results-when-using-getcoupon/58726>\
**Category:** Ask the community\
**Created:** [May 2, 2024, 7:05am UTC](https://forum.wixstudio.com/t/undefined-results-when-using-getcoupon/58726 "2024-05-02T07:05:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Baksheesh](https://avatars.discourse-cdn.com/v4/letter/b/71c47a/32.png) [@Baksheesh](https://forum.wixstudio.com/u/Baksheesh)\
**Post date:** [May 2, 2024, 7:05am UTC](https://forum.wixstudio.com/t/undefined-results-when-using-getcoupon/58726/1 "2024-05-02T07:05:44Z")

</div>

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”.

```javascript
type or paste code here

```

Backend file GetCoupon.jsw

```javascript
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:

```javascript

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);
    });
});

```

---

<div class="post-metadata">

**Author:** ![anthony](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/anthony/32/79536_2.png) [@anthony](https://forum.wixstudio.com/u/anthony)\
**Post date:** [May 3, 2024, 7:21pm UTC](https://forum.wixstudio.com/t/undefined-results-when-using-getcoupon/58726/2 "2024-05-03T19:21:39Z")

</div>

> [@Baksheesh](#):
>
> ```javascript
> const result = await coupons.getCoupon(id);
> 
> ```

`getCoupon` needs to be elevated to work: [elevate - Velo API Reference - Wix.com](https://www.wix.com/velo/reference/wix-auth/elevate)

 ![image](https://us1.discourse-cdn.com/wix/original/3X/3/c/3c787e14424683e2a6e22d84fa5d12fad6b5edf4.png)

---

<div class="post-metadata">

**Author:** ![Baksheesh](https://avatars.discourse-cdn.com/v4/letter/b/71c47a/32.png) [@Baksheesh](https://forum.wixstudio.com/u/Baksheesh)\
**Post date:** [May 5, 2024, 9:35am UTC](https://forum.wixstudio.com/t/undefined-results-when-using-getcoupon/58726/3 "2024-05-05T09:35:36Z")

</div>

Ok, permissions required. I think the docs on getCoupon() should at least show one example of how to structure the elevated call if that’s the only way it can be run.

My backend .jsw file now looks like this, but still returns everything as “undefined”.

```javascript
import { coupons } from 'wix-marketing.v2';
import * as wixAuth from 'wix-auth';
import { elevate } from 'wix-auth';

const elevatedGetCoupon = wixAuth.elevate(coupons.getCoupon);

export async function getCoupon(id) {
  return elevatedGetCoupon(id)
    .then((result) => {
      return result;
    })
    .catch((error) => {
      console.log(error);
    });
}

```

---

<div class="post-metadata">

**Author:** ![Baksheesh](https://avatars.discourse-cdn.com/v4/letter/b/71c47a/32.png) [@Baksheesh](https://forum.wixstudio.com/u/Baksheesh)\
**Post date:** [May 19, 2024, 3:57am UTC](https://forum.wixstudio.com/t/undefined-results-when-using-getcoupon/58726/4 "2024-05-19T03:57:59Z")

</div>

any ideas why elevate getcoupon() isn’t working here? The Wix docs are very vague.
