earnPoints( )


Adds points to a loyalty account.

The earnPoints() function returns a Promise that resolves to the updated loyalty account.

Only a positive amount can be added using the earnPoints() function, to manually adjust an account's balance for a negative amount, use adjustPoints().

The earnPoints() function allows customers to manually earn points to their loyalty accounts. To use this function you must include an appId and an idempotencyKey. Any string can be set as the appId or idempotencyKey. In contrast to when an account earns points through an action taken on your site, the appId automatically sets to the source app that generates the points. The transaction type is "EARN" for points earned this way.

Note: Only visitors with Manage Loyalty permissions can earn loyalty points.

Authentication
  • When developing websites or building an app with Blocks, this method may require elevated permissions, depending on the identity of the user calling it and the calling user’s permissions.
  • When building apps without Blocks or for headless projects, you can only call this method directly when authenticated as a Wix app or Wix user identity. When authenticated as a different identity, you can call this method using elevation.
  • Elevation permits users to call methods they typically cannot access. Therefore, you should only use it intentionally and securely.
Permissions
Manage Loyalty
Learn more about app permissions.
Method Declaration
Copy
function earnPoints(
  accountId: string,
  options: EarnPointsOptions,
): Promise<EarnPointsResponse>;
Method Parameters
accountIdstringRequired

Loyalty account ID.


optionsEarnPointsOptions

Earn points info.

Returns
Return Type:Promise<EarnPointsResponse>
JavaScript
import { accounts } from "@wix/loyalty"; /* Sample accountId value: '6d2c421e-3c1a-4464-bf2f-df13a3fc8aea' * * Sample options value: * { * 'amount': 50, * 'description': 'Subscribed to newsletter.', * 'appId': '553c79f3-5625-4f38-b14b-ef7c0d1e87df', * 'idempotencyKey': 'bfdc785c-bbc6-447d-b987-220ca649a3b2' * } */ export async function myEarnPointsFunction(accountId, Option) { try { const updatedAccount = await accounts.earnPoints(accountId, Option); const newBalance = updatedAccount.account.points.balance; const transactionId = updatedAccount.transactionId; console.log("Success! New balance is ", newBalance); return updatedAccount; } catch (error) { console.error(error); } } /* Promise resolves to: * { * "transaction_id": "4dd51f9d-2664-420a-9802-4df7811a5221", * "account": { * "_id": "6d2c421e-3c1a-4464-bf2f-df13a3fc8aea", * "contactId": "7fa15d5e-49c4-44ef-8111-4cb0a04ca4db", * "memberId": "7fa15d5e-49c4-44ef-8111-4cb0a04ca4db", * "points": { * "balance": 185, * "earned": 185, * "adjusted": 0, * "redeemed": 0 * }, * "rewardAvailable": true, * "_createdDate": "2022-11-09T15:18:53.582Z", * "_updatedDate": "2022-11-28T14:48:59.940Z", * "revision": "6", * "tier": { * "_updatedDate": "2022-11-28T14:48:59.939Z", * "points": 185 * } * } * } */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?