# Adding loyalty points to a member's account

**URL:** <https://forum.wixstudio.com/t/adding-loyalty-points-to-a-members-account/71717>\
**Category:** Ask the community\
**Tags:** wix-loyalty-v2, question, code\
**Created:** [June 24, 2025, 9:08am UTC](https://forum.wixstudio.com/t/adding-loyalty-points-to-a-members-account/71717 "2025-06-24T09:08:02Z")\
**Posts on this page:** 5\
**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:** [June 24, 2025, 9:08am UTC](https://forum.wixstudio.com/t/adding-loyalty-points-to-a-members-account/71717/1 "2025-06-24T09:08:02Z")

</div>

I have an automation that awards new members 50 loyalty points, but can’t figure out how to add additional points to their account with code. When I run the code nothing happens, literally. Seems to get stuck on loading the backend files (which are identical to the WIx examples, and show no errors). Nothing goes to the console log.

frontend:

```javascript
import { awardLoyaltyPoints } from "backend/AwardLoyaltyPoints.web.js";
import { getLoyaltyAccountID } from "backend/GetLoyaltyPointsAccount.web.js";

$w.onReady(async function () {

  let opt = {
    contactId: "0af9f886-b446-44fd-9787-6ef48a368736"// Sample member's contact ID.
  }
  console.log("Processing order :" + opt);
  
  let loyaltyID = await getLoyaltyAccountID(opt);
  console.log("Will attempt to award 50 points to :" + loyaltyID);

  let success = await AwardPoints(loyaltyID);
  console.log ("Backend Award points: " + success)
  
});

function AwardPoints(loyalID){
  let opts = {
    amount: 50,
    description: "Earn 50 points for booking an order",
    appId: "553c79f3-5625-4f38-b14b-ef7c0d1e87df", //Wix sample
    idempotencyKey: "bfdc785c-bbc6-447d-b987-220ca649a3b2" //Wix sample
   }
  return awardLoyaltyPoints(loyalID, opts)
}

```

backend:  
GetLoyaltyPointsAccount.web.js

```javascript
import { Permissions, webMethod } from "wix-web-module";
import { accounts } from "wix-loyalty.v2";

export const getLoyaltyAccountID = webMethod(
  Permissions.Anyone,
  async (options) => {
    try {
      const loyaltyAccount = await accounts.getAccountBySecondaryId(options);

      const accountId = loyaltyAccount.account._id;
      const currentRevision = loyaltyAccount.account.revision;

      console.log(
        "Success! This site contact's loyalty account ID is: ",
        accountId,
      );

      return loyaltyAccount;
    } catch (error) {
      console.error(error);
    }
  },
);

```

AwardLoyaltyPoints.web.js

```javascript
import { Permissions, webMethod } from "wix-web-module";
import { accounts } from "wix-loyalty.v2";

export const awardLoyaltyPoints = webMethod(Permissions.Anyone, async (accountId, options) => {
  try {
    const updatedAccount = await accounts.earnPoints(accountId, options);

    const newBalance = updatedAccount.account.points.balance;
    //const transactionId = updatedAccount.transaction_id;

    console.log("Success! New balance is ", newBalance);
    return updatedAccount;
  } catch (error) {
    console.error(error);
  }
});

```

---

<div class="post-metadata">

**Author:** ![noahlovell](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/noahlovell/32/118920_2.png) [@noahlovell](https://forum.wixstudio.com/u/noahlovell)\
**Post date:** [June 24, 2025, 1:57pm UTC](https://forum.wixstudio.com/t/adding-loyalty-points-to-a-members-account/71717/2 "2025-06-24T13:57:49Z")

</div>

I haven’t jumped into the code, or what it’s doing yet, but notice you’re calling your backend functions to the page code as `.js` files.

To expose these functions and allow them to be called from the frontend, they need to be within `.web.js` files. (You’ve already got them written as web methods, which is great!)

---

<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:** [June 25, 2025, 1:47am UTC](https://forum.wixstudio.com/t/adding-loyalty-points-to-a-members-account/71717/3 "2025-06-25T01:47:56Z")

</div>

Yes, you were correct about the backend file names. I have updated the code in my post above and it runs, but doesn’t get very far.

GetLoyaltyPointsAccount.web.js returns a permission denied error: ‘LOYALTY.READ\_ACCOUNTS required to call this endpoint.: Forbidden’

I also rechecked the contact ID to ensure that it was the contact ID of a member that already has loyalty points, and tried a few other contact IDs as well but this did not make any difference.

---

<div class="post-metadata">

**Author:** ![noahlovell](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/noahlovell/32/118920_2.png) [@noahlovell](https://forum.wixstudio.com/u/noahlovell)\
**Post date:** [June 25, 2025, 8:46am UTC](https://forum.wixstudio.com/t/adding-loyalty-points-to-a-members-account/71717/4 "2025-06-25T08:46:15Z")

</div>

Taking a quick read over the docs, some methods require elevated permissions (like `accounts.getAccountBySecondaryId()`)

![Screenshot 2025-06-25 at 9.45.11](https://us1.discourse-cdn.com/wix/original/3X/c/e/ceea185894b51a536e37aada9b07616bc28ac379.png)

* * *

The docs for setting up elevate are here - [Elevate | Velo](https://dev.wix.com/docs/velo/apis/wix-auth/elevate) 🙂

---

<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:** [June 25, 2025, 1:15pm UTC](https://forum.wixstudio.com/t/adding-loyalty-points-to-a-members-account/71717/5 "2025-06-25T13:15:25Z")

</div>

Really wish the API docs would show a working sample of an elevated call for any function that requires it. But I did manage to figure it out and get it working, and corrected a few minor errors. I’m posting my working code here for the community. 😁

```javascript
import { awardLoyaltyPoints } from "backend/AwardLoyaltyPoints.web.js";
import { getLoyaltyAccountID } from "backend/GetLoyaltyPointsAccount.web.js";

$w.onReady(async function () {

  let opt = {
    contactId: "0af9f886-b446-44fd-9787-6ef48a368736"// CairoCorrespondent ID
  }
    
  let loyaltyAccount = await getLoyaltyAccountID(opt); // CairoCorrespondent ID
  
  const accountId = loyaltyAccount.account._id;
  const currentPoints = loyaltyAccount.account.points.balance;

  console.log("Loyalty account ID: " + accountId);
  console.log("Current points: " + loyaltyAccount.account.points.balance);
  
  console.log("Will attempt to award 50 points to :" + accountId);

  let options = {
    "amount": 50,
    "description": "Earn 50 points for booking an order",
    "appId": "553c79f3-5625-4f38-b14b-ef7c0d1e87df", // Wix appId for points added manually
    "idempotencyKey": "bfdc785c-bbc6-447d-b987-220ca649a3b2" // Wix sample
  }

  const updatedAccount = await awardLoyaltyPoints(accountId, options)
  const newBalance = updatedAccount.account.points.balance;
  console.log ("Loyalty points, updated balance: " + newBalance)

});

```

GetLoyaltyPointsAccount.web.js

```javascript
import { Permissions, webMethod } from "wix-web-module";
import { accounts } from "wix-loyalty.v2";
import { elevate } from "wix-auth";

export const getLoyaltyAccountID = webMethod( Permissions.Anyone, 
  async (options) => {
  try {
    const elevatedAccounts = elevate(accounts.getAccountBySecondaryId);
    const loyaltyAccount = await elevatedAccounts(options);

    return loyaltyAccount;
  } catch (error) {
    console.error(error);
  }
});

```

AwardLoyaltyPoints.web.js

```javascript
import { Permissions, webMethod } from "wix-web-module";
import { accounts } from "wix-loyalty.v2";
import { elevate } from "wix-auth";

export const awardLoyaltyPoints = webMethod( Permissions.Anyone, 
  async (accountId, options) => {
  try {
    const elevatedEarnPoints = elevate(accounts.earnPoints);
    const updatedAccount = await elevatedEarnPoints(accountId, options);
    return updatedAccount;
    
  } catch (error) {
    console.error(error);
  }
});

```
