> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# AdjustPoints

# Package: accounts

# Namespace: LoyaltyAccounts

# Method link: https://dev.wix.com/docs/api-reference/crm/loyalty-program/accounts/accounts/adjust-points.md

## Permission Scopes:
Manage Loyalty: SCOPE.DC-LOYALTY.MANAGE-LOYALTY

## Introduction

Adjusts the point balance of a loyalty account.

You can adjust the balance in two ways:
- `balance` allows you to set the total points balance to this new amount. The transaction `type` will return as `"ADJUST"`.
- `amount` allows you to adjust the points balance by this amount. This amount can be a positive number to increase the points balance or a negative number to decrease the balance. The transaction `type` will return as `"GIVE"`.

An account may not be adjusted to result in a negative balance. If you pass an integer in both the `balance` and the `amount` parameters then the `balance` adjustment takes effect and the
`amount` adjustment is ignored.

---

## REST API

### Schema

```
 Method: adjustPoints
 Description: Adjusts the point balance of a loyalty account.  You can adjust the balance in two ways: - `balance` allows you to set the total points balance to this new amount. The transaction `type` will return as `"ADJUST"`. - `amount` allows you to adjust the points balance by this amount. This amount can be a positive number to increase the points balance or a negative number to decrease the balance. The transaction `type` will return as `"GIVE"`.  An account may not be adjusted to result in a negative balance. If you pass an integer in both the `balance` and the `amount` parameters then the `balance` adjustment takes effect and the `amount` adjustment is ignored.
 URL: https://www.wixapis.com/loyalty-accounts/v1/accounts/{accountId}/adjust-points
 Method: POST
 Method parameters:
   param name: description | type: description | description: Description to explain the reason for the points adjustment.  | validation: minLength 1, maxLength 100
   param name: revision | type: revision | description: Each time the loyalty account is updated, `revision` increments by 1.  The current `revision` must be passed when adjusting points in the loyalty account. This ensures you're working with the latest version of the loyalty account and prevents unintended overwrites.  | validation: minimum 1
    - ONE-OF: 
     - name: balance | type: integer | description: Sets the account's point balance to this amount. Must be a positive, whole number or zero.  The net difference between this new balance and the previous balance will be reflected in the `adjusted` field of the customer's account.  Min: `0`  Max: `999999999`  | validation: minimum 0, maximum 999999999
     - name: amount | type: integer | description: Adjusts the account's point balance by this amount. Must be a whole number with a maximum of 7 digits. The amount can be negative, but cannot be `0`.  Min: `-9999999`  Max: `9999999`  | validation: minimum -9999999, maximum 9999999
 Return type: AdjustPointsResponse
  - name: account | type: LoyaltyAccount | description: Loyalty account.  
     - name: id | type: string | description: Account GUID.  | read-only: true | validation: format GUID
     - name: contactId | type: string | description: Account owner's contact GUID. See the Contacts API to learn more about a site's contacts.  | read-only: true | validation: format GUID
     - name: memberId | type: string | description: Member GUID of the account owner. See the Members API to learn more about a site's members.  | read-only: true | validation: format GUID
     - name: points | type: Points | description: Details of the account's point totals.  | read-only: true 
        - name: balance | type: integer | description: Current points balance.  Equal to the sum of `earned` and `adjusted` points, minus `redeemed` points.  | read-only: true | validation: minimum 0
        - name: earned | type: integer | description: Total earned points.  | read-only: true | validation: minimum 0
        - name: adjusted | type: integer | description: Total adjusted points.  | read-only: true | validation: minimum 0
        - name: redeemed | type: integer | description: Total redeemed points.  | read-only: true | validation: minimum 0
        - name: expired | type: integer | description: Total expired points.  | read-only: true | validation: minimum 0
     - name: rewardAvailable | type: boolean | description: Whether the account has enough points in `points.balance` to redeem for a reward.  | read-only: true 
     - name: createdDate | type: string | description: Date and time the account was created.  | read-only: true | validation: format date-time
     - name: updatedDate | type: string | description: Date and time the account was last updated.  | read-only: true | validation: format date-time
     - name: lastActivityDate | type: string | description: Date and time of the account's last activity.  | read-only: true | validation: format date-time
     - name: revision | type: number | description: Revision number, which increments by 1 each time the loyalty account is updated.  To prevent conflicting changes, the current `revision` must be passed when updating the loyalty account.  Ignored when creating an account.  
     - name: tier | type: Tier | description: Tier information.  See the Tiers API for more information.  | read-only: true 
        - name: id | type: string | description: Tier GUID.  This field will not be returned if the account belongs to the base tier.  | read-only: true | validation: format GUID
        - name: updatedDate | type: string | description: Date and time the tier information was last recalculated.  | read-only: true | validation: format date-time
        - name: points | type: integer | description: Points earned and adjusted over the tier's current rolling window.  | read-only: true | validation: minimum 0
     - name: contact | type: Contact | description: Contact information.  | read-only: true 
        - name: id | type: string | description: Contact GUID.  | read-only: true | validation: format GUID
        - name: name | type: string | description: Contact's first and last name.  | read-only: true 
        - name: picture | type: Image | description: Contact's profile picture.  | read-only: true 
           - name: id | type: string | description: WixMedia image GUID.  
           - name: url | type: string | description: Image URL.  
           - name: height | type: integer | description: Original image height.  | read-only: true 
           - name: width | type: integer | description: Original image width.  | read-only: true 
        - name: email | type: string | description: Contact's email address.  | read-only: true | validation: format EMAIL
        - name: displayName | type: string | description: Contact's first and last name. If no name is provided, uses contact's email.  | read-only: true 
     - name: pointsExpiration | type: PointsExpiration | description: Points expiration information.  | read-only: true 
        - name: expirationDate | type: string | description: Date and time at which points are expiring.  | read-only: true | validation: format date-time
        - name: expiringPointsAmount | type: integer | description: Amount of points that are going to expire at that date.  | read-only: true 
  - name: transactionId | type: string | description: Transaction GUID associated with the points adjustment.  | read-only: true | validation: format GUID


```

### Examples

### Adjust account balance
```curl
curl -X POST \
  'https://www.wixapis.com/loyalty-accounts/v1/accounts/e6f39a5b-a6d0-4556-b889-0cf09d8a84f7/adjust-points' \
  -H 'Authorization: <AUTH>' \
  -H 'Content-Type: application/json' \
  --data-raw '{
        "accountId": "01e34b81-4e48-43e4-b178-c84f3b968574",
        "description": "Sync from external program",
        "balance": 15,
        "revision": "3"
  }'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.loyalty.accounts.adjustPoints(accountId, options)
 Description: Adjusts the point balance of a loyalty account.  You can adjust the balance in two ways: - `balance` allows you to set the total points balance to this new amount. The transaction `type` will return as `"ADJUST"`. - `amount` allows you to adjust the points balance by this amount. This amount can be a positive number to increase the points balance or a negative number to decrease the balance. The transaction `type` will return as `"GIVE"`.  An account may not be adjusted to result in a negative balance. If you pass an integer in both the `balance` and the `amount` parameters then the `balance` adjustment takes effect and the `amount` adjustment is ignored.
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  accountId
 Method parameters: 
   param name: accountId | type: string | description: Loyalty account GUID. | required: true | validation: format GUID
   param name: options | type: AdjustPointsOptions  none  
    - ONE-OF: 
     - name: balance | type: integer | description: Sets the account's point balance to this amount. Must be a positive, whole number or zero.  The net difference between this new balance and the previous balance will be reflected in the `adjusted` field of the customer's account.  Min: `0`  Max: `999999999`  | validation: minimum 0, maximum 999999999
     - name: amount | type: integer | description: Adjusts the account's point balance by this amount. Must be a whole number with a maximum of 7 digits. The amount can be negative, but cannot be `0`.  Min: `-9999999`  Max: `9999999`  | validation: minimum -9999999, maximum 9999999
        - name: description | type: string | description: Description to explain the reason for the points adjustment.  | validation: minLength 1, maxLength 100
        - name: revision | type: number | description: Each time the loyalty account is updated, `revision` increments by 1.  The current `revision` must be passed when adjusting points in the loyalty account. This ensures you're working with the latest version of the loyalty account and prevents unintended overwrites.  | validation: minimum 1
 Return type: PROMISE<AdjustPointsResponse>
  - name: account | type: LoyaltyAccount | description: Loyalty account.  
     - name: _id | type: string | description: Account GUID.  | read-only: true | validation: format GUID
     - name: contactId | type: string | description: Account owner's contact GUID. See the Contacts API to learn more about a site's contacts.  | read-only: true | validation: format GUID
     - name: memberId | type: string | description: Member GUID of the account owner. See the Members API to learn more about a site's members.  | read-only: true | validation: format GUID
     - name: points | type: Points | description: Details of the account's point totals.  | read-only: true 
        - name: balance | type: integer | description: Current points balance.  Equal to the sum of `earned` and `adjusted` points, minus `redeemed` points.  | read-only: true | validation: minimum 0
        - name: earned | type: integer | description: Total earned points.  | read-only: true | validation: minimum 0
        - name: adjusted | type: integer | description: Total adjusted points.  | read-only: true | validation: minimum 0
        - name: redeemed | type: integer | description: Total redeemed points.  | read-only: true | validation: minimum 0
        - name: expired | type: integer | description: Total expired points.  | read-only: true | validation: minimum 0
     - name: rewardAvailable | type: boolean | description: Whether the account has enough points in `points.balance` to redeem for a reward.  | read-only: true 
     - name: _createdDate | type: Date | description: Date and time the account was created.  | read-only: true 
     - name: _updatedDate | type: Date | description: Date and time the account was last updated.  | read-only: true 
     - name: lastActivityDate | type: Date | description: Date and time of the account's last activity.  | read-only: true 
     - name: revision | type: number | description: Revision number, which increments by 1 each time the loyalty account is updated.  To prevent conflicting changes, the current `revision` must be passed when updating the loyalty account.  Ignored when creating an account.  
     - name: tier | type: Tier | description: Tier information.  See the Tiers API for more information.  | read-only: true 
        - name: _id | type: string | description: Tier GUID.  This field will not be returned if the account belongs to the base tier.  | read-only: true | validation: format GUID
        - name: _updatedDate | type: Date | description: Date and time the tier information was last recalculated.  | read-only: true 
        - name: points | type: integer | description: Points earned and adjusted over the tier's current rolling window.  | read-only: true | validation: minimum 0
     - name: contact | type: Contact | description: Contact information.  | read-only: true 
        - name: _id | type: string | description: Contact GUID.  | read-only: true | validation: format GUID
        - name: name | type: string | description: Contact's first and last name.  | read-only: true 
        - name: picture | type: Image | description: Contact's profile picture.  | read-only: true 
           - name: _id | type: string | description: WixMedia image GUID.  
           - name: url | type: string | description: Image URL.  
           - name: height | type: integer | description: Original image height.  | read-only: true 
           - name: width | type: integer | description: Original image width.  | read-only: true 
        - name: email | type: string | description: Contact's email address.  | read-only: true | validation: format EMAIL
        - name: displayName | type: string | description: Contact's first and last name. If no name is provided, uses contact's email.  | read-only: true 
     - name: pointsExpiration | type: PointsExpiration | description: Points expiration information.  | read-only: true 
        - name: expirationDate | type: Date | description: Date and time at which points are expiring.  | read-only: true 
        - name: expiringPointsAmount | type: integer | description: Amount of points that are going to expire at that date.  | read-only: true 
  - name: transactionId | type: string | description: Transaction GUID associated with the points adjustment.  | read-only: true | validation: format GUID


```

### Examples

### Get a loyalty account's latest revision, then give points to the account (with elevated permissions)
First, retrieve the account using `getAccount()`. Then, extract the `revision` and pass it to `options` argument for the `adjustPoints()` function.

```javascript
import { accounts } from "@wix/loyalty";
import { auth } from '@wix/essentials';

// Sample accountId value: "1ab8f49c-a329-4ddc-a31d-814afbb3b565".

/* Sample options value:
 * {
 *   "amount": 50,
 *   "description": "Shared on social media."
 * }
 */

export async function myGetRevisionAndAdjustPointsFunction(accountId, options) {
  const elevatedGetLoyaltyAccount = auth.elevate(accounts.getAccount);
  const retrievedLoyaltyAccount = await elevatedGetLoyaltyAccount(accountId);
  const currentRevision = retrievedLoyaltyAccount.revision;

  options.revision = currentRevision;

  const elevatedAdjustPoints = auth.elevate(accounts.adjustPoints);

  try {
    const updatedAccount = await elevatedAdjustPoints(accountId, options);

    const updatedBalance = updatedAccount.account.points.balance;
    const transactionId = updatedAccount.transactionId;

    console.log(
      "Success! New account balance is: ",
      updatedBalance,
      ". This ID for this transaction is: ",
      transactionId
    );

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

/* Promise resolves to:
 * {
 *   "transaction_id": "060e672a-d86b-4761-b587-1e97a34fd2f6",
 *   "account": {
 *     "_id": "1ab8f49c-a329-4ddc-a31d-814afbb3b565",
 *     "contactId": "3128dc64-74fc-442f-aa32-e8e871dad141",
 *     "memberId": "3128dc64-74fc-442f-aa32-e8e871dad141",
 *     "points": {
 *       "balance": 295,
 *       "earned": 45,
 *       "adjusted": 250,
 *       "redeemed": 0
 *     },
 *     "rewardAvailable": true,
 *     "_createdDate": "2022-11-28T11:57:30.722Z",
 *     "_updatedDate": "2023-01-19T12:03:16.946Z",
 *     "lastActivityDate": "2023-01-19T12:03:16.945Z",
 *     "revision": "19",
 *     "tier": {
 *       "_id": "65fdf385-37b9-42e8-81c8-2e5fafe446f0",
 *       "_updatedDate": "2023-01-19T12:03:16.945Z",
 *       "points": 295
 *     }
 *   }
 * }
 */
```

### Get a loyalty account's latest revision, then give points to the account
First, retrieve the account using `getAccount()`. Then, extract the `revision` and pass it to `options` argument for the `adjustPoints()` function.

```javascript
import { accounts } from "@wix/loyalty";

// Sample accountId value: "1ab8f49c-a329-4ddc-a31d-814afbb3b565".

/* Sample options value:
 * {
 *   "amount": 50,
 *   "description": "Shared on social media."
 * }
 */

export async function myGetRevisionAndAdjustPointsFunction(accountId, options) {
  const retrievedLoyaltyAccount = await accounts.getAccount(accountId);
  const currentRevision = retrievedLoyaltyAccount.revision;

  options.revision = currentRevision;

  try {
    const updatedAccount = await accounts.adjustPoints(accountId, options);

    const updatedBalance = updatedAccount.account.points.balance;
    const transactionId = updatedAccount.transactionId;

    console.log(
      "Success! New account balance is: ",
      updatedBalance,
      ". This ID for this transaction is: ",
      transactionId
    );

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

/* Promise resolves to:
 * {
 *   "transaction_id": "060e672a-d86b-4761-b587-1e97a34fd2f6",
 *   "account": {
 *     "_id": "1ab8f49c-a329-4ddc-a31d-814afbb3b565",
 *     "contactId": "3128dc64-74fc-442f-aa32-e8e871dad141",
 *     "memberId": "3128dc64-74fc-442f-aa32-e8e871dad141",
 *     "points": {
 *       "balance": 295,
 *       "earned": 45,
 *       "adjusted": 250,
 *       "redeemed": 0
 *     },
 *     "rewardAvailable": true,
 *     "_createdDate": "2022-11-28T11:57:30.722Z",
 *     "_updatedDate": "2023-01-19T12:03:16.946Z",
 *     "lastActivityDate": "2023-01-19T12:03:16.945Z",
 *     "revision": "19",
 *     "tier": {
 *       "_id": "65fdf385-37b9-42e8-81c8-2e5fafe446f0",
 *       "_updatedDate": "2023-01-19T12:03:16.945Z",
 *       "points": 295
 *     }
 *   }
 * }
 */
```

### Adjust loyalty account balance (with elevated permissions)
```javascript
import { accounts } from '@wix/loyalty';
import { auth } from '@wix/essentials';

// Sample accountId value: "1ab8f49c-a329-4ddc-a31d-814afbb3b565";

/* Sample options values:
*  {
*    balance: 715,
*    description: "Sync from external program.",
*    revision: "3"
*   };
*/

const elevatedAdjustPoints = auth.elevate(accounts.adjustPoints);

export async function myAdjustPointsFunction(accountId, options) {
  try {
    const updatedAccount = await elevatedAdjustPoints(accountId, options);

    const updatedBalance = updatedAccount.account.points.balance;
    const transactionId = updatedAccount.transactionId;

    console.log('Success! New account balance is: ', updatedBalance, ' The ID for this transaction is: ', transactionId);  

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

/* Promise resolves to:
 * {
 *   "transaction_id": "1ab8f49c-a329-4ddc-a31d-814afbb3b565",
 *   "account": {
 *     "_id": "1ab8f49c-a329-4ddc-a31d-814afbb3b565",
 *     "contactId": "3128dc64-74fc-442f-aa32-e8e871dad141",
 *     "memberId": "3128dc64-74fc-442f-aa32-e8e871dad141",
 *     "points": {
 *       "balance": 715,
 *       "earned": 0,
 *       "adjusted": 715,
 *       "redeemed": 0
 *     },
 *     "rewardAvailable": false,
 *     "_createdDate": "2022-11-28T11:57:30.722Z",
 *     "_updatedDate": "2023-01-17T12:04:49.620Z",
 *     "lastActivityDate": "2023-01-17T12:04:49.619Z",
 *     "revision": "2",
 *     "tier": {
 *       "_id": "05e9d924-54c4-4540-94ef-8edd1e303611",
 *       "_updatedDate": "2023-01-17T12:04:49.619Z",
 *       "points": 715
 *     }
 *   }
 * }
 */
```

### Adjust loyalty account balance
```javascript
import { accounts } from '@wix/loyalty';

// Sample accountId value: "1ab8f49c-a329-4ddc-a31d-814afbb3b565";

/* Sample options values:
 *  {
 *    balance: 715,
 *    description: "Sync from external program.",
 *    revision: "3"
 *   };
 */

export async function myAdjustPointsFunction(accountId, options) {
  try {
    const updatedAccount = await accounts.adjustPoints(accountId, options);

    const updatedBalance = updatedAccount.account.points.balance;
    const transactionId = updatedAccount.transactionId;

    console.log('Success! New account balance is: ', updatedBalance, ' The ID for this transaction is: ', transactionId);  

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

/* Promise resolves to:
 * {
 *   "transaction_id": "1ab8f49c-a329-4ddc-a31d-814afbb3b565",
 *   "account": {
 *     "_id": "1ab8f49c-a329-4ddc-a31d-814afbb3b565",
 *     "contactId": "3128dc64-74fc-442f-aa32-e8e871dad141",
 *     "memberId": "3128dc64-74fc-442f-aa32-e8e871dad141",
 *     "points": {
 *       "balance": 715,
 *       "earned": 0,
 *       "adjusted": 715,
 *       "redeemed": 0
 *     },
 *     "rewardAvailable": false,
 *     "_createdDate": "2022-11-28T11:57:30.722Z",
 *     "_updatedDate": "2023-01-17T12:04:49.620Z",
 *     "lastActivityDate": "2023-01-17T12:04:49.619Z",
 *     "revision": "2",
 *     "tier": {
 *       "_id": "05e9d924-54c4-4540-94ef-8edd1e303611",
 *       "_updatedDate": "2023-01-17T12:04:49.619Z",
 *       "points": 715
 *     }
 *   }
 * }
 */
```

### adjustPoints (self-managed)
Self-managed SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { accounts } from '@wix/loyalty';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { accounts },
  // Include the auth strategy and host as relevant
});


async function adjustPoints(accountId,options) {
  const response = await myWixClient.accounts.adjustPoints(accountId,options);
};
```

---