# REST API with WPLoyalty PRO Plugin

The WPLoyalty REST API enables users to perform two actions:&#x20;

* add points&#x20;
* reduce points.&#x20;

This document provides a guide on how to use the REST API to perform these actions using the [WPLoyalty PRO](https://wployalty.net/) plugin.&#x20;

\
Please note that before proceeding, you must have installed and activated the WPLoyalty PRO plugin. It is important to note that this feature requires the PRO version.&#x20;

[Click here to purchase WPLoyalty PRO.](https://wployalty.net/)

\
Let’s get started,

**Step 1: Creating REST API credentials**&#x20;

* Go to WordPress backend -> Woocommerce -> Settings -> Advanced.&#x20;
* Under REST API, click on the "add key" button.

<figure><img src="https://lh5.googleusercontent.com/51hVPZOot8ubutB7APNrd6hT8K3Y98y8QghX3SkePlibGvWdm8PTAOgA_ITCaNePlo1OofZ4ECHXxqnPzXf5kVcB6Gx4jtIQDaVGhT6PVZcBoOnvkPWlIJmR9vadX3_3gRcRSRXkh6ZMabJGgZmPVPc" alt=""><figcaption></figcaption></figure>

**Step 2: Generating API key:**&#x20;

* Give a description and set the permission as Read/Write which can be set as Read/Write according to your specific needs.
* Click on "Generate API key" to proceed.

<figure><img src="https://lh5.googleusercontent.com/vT7gQGw4VDyMc-g8wbov8LwgLmJ1uq1kv8-S0rB35ychbUMEIcA7UfnEH8U5nnadvCGvXzEFZjWa5OHxMRkPt09tmhpCJONGlFcUZ3XaLegHLwDbTgQuk8QugE5bNnvtGK5mOpWpht8YicCHnF5G5qY" alt=""><figcaption></figcaption></figure>

**Step 3: Getting REST API credentials**&#x20;

Now, you will get an consumer key and consumer secret from woocommerce.&#x20;

<figure><img src="https://lh4.googleusercontent.com/xGwUmKZPnw0-g-hpImMEyL0LHZWyL9Fc0uuzdDSJfNfIv0igMmMx-1sOsbeE-_d17qVdr_sUsGJn74W28e-nbeWHDZ0Twb8WsJmBxYd32A4meYHKODaIRND_sXuN39J80VpFFU0MQn_eGzTaA6lF3G4" alt=""><figcaption></figcaption></figure>

**Note:** Make sure to save a copy of your new keys locally because the secret key will no longer be visible once you navigate away from this page.

**To Add Points:**&#x20;

POST  `/wp-json/wc/v3/wployalty/customers/points/add`

To authenticate the API:  Woocommerce provides supported authentication.

Parameters/ attributes:

| Field       | Required | Field Type | Description                 |
| ----------- | -------- | ---------- | --------------------------- |
| user\_email | yes      | email      | WPLoyalty customer email ID |
| points      | yes      | int        | amount of points to add     |

\
Note: If the email ID is not present in the WPLoyalty Customer list, a new customer record will be created in the WPLoyalty Customer Dashboard while adding points. Please note that authentication is handled by Woocommerce, and WPLoyalty supports the actions to add/ reduce points.

\
\
**To Reduce Points:**&#x20;

POST `/wp-json/wc/v3/wployalty/customers/points/reduce`

To authenticate the API:  Woocommerce provides supported authentication.&#x20;

**Parameters/ attributes:**

| Field       | Required | Field Type | Description                 |
| ----------- | -------- | ---------- | --------------------------- |
| user\_email | yes      | email      | WPLoyalty customer email ID |
| points      | yes      | int        | amount of points to reduce  |

**Error code for both add/ reduce points:**&#x20;

| Error code           | Response Error Code | Message                                                |
| -------------------- | ------------------- | ------------------------------------------------------ |
| rest\_invalid\_param | 400                 | Invalid parameter(s) : user\_email, points             |
| rest\_no\_route      | 404                 | No route was found matching the URL and request method |

This above discussed feature is only available in the WPLoyalty PRO version. To access it, click on the

[Click here to purchase WPLoyalty PRO.](https://wployalty.net/)

**Next Steps:**&#x20;

Learn more about WPLoyalty and related guides:

* [Click here to learn more about WPLoyalty Customer tab and import option](https://docs.wployalty.net/customers-levels-and-vip/importing-customers-and-points)
* [Learn about how to provide Points while purchasing](https://docs.wployalty.net/campaign-types/points-for-purchase)
* [Learn how to convert earned Points to a Reward/ Discount ](https://docs.wployalty.net/reward-types/points-conversion)
* [Available types of Campings in WPLoyalty ](https://docs.wployalty.net/campaigns/campaign-types)
* [Checkout our cool Launcher Widget ](https://docs.wployalty.net/add-ons/wployalty-launcher)

**Still unclear ?**&#x20;

Please submit a [support request.](https://wployalty.net/support/) We are always happy to assist you :)<br>
