# Public API action methods

This will cover all the posting data Javascript methods of the `joyInstance` object. These methods will take action on behalf of the current user such as: redeeming points, and getting referral links.

### Redeem a program

This method will call an API request to redeem the customer's balance for a coupon.\
It normally takes **2 parameters**: `programId` and `points` (optional).

* For fixed-point programs like **"Get 10% off for 100 points"**, the `points` parameter is not required.
* For dynamic redeem programs, customers must provide the number of points they want to redeem.

Additional parameter for Free Gift programs:

If the program type is **Free gift** and uses the option **"Free one product from selection"**, the method supports an additional **optional** parameter:

* `variantIdSelected` *(optional)* — the variant ID of the selected free gift product.

```javascript
joyInstance.redeem(programId, points, variantIdSelected).then(function(resp){
    console.log(resp)
});
```

Sample response:

```json
{
    "customer": {
        "id": "avsu0TQoHYd4Zq5TZnJg",
        "shopifyCustomerId": 6858989109535,
        "earnSignUp": true,
        "name": "admin super",
        "hasPoint": true,
        "state": "enabled",
        "shopId": "7vqeDbhZtyofeuH7l1ky",
        "type": "member",
        "acceptsMarketing": false,
        "urlReferral": "https://inviteee.to/i/5Nuw",
        "email": "anhth@avada.email",
        "createdAt": "2023-04-04T07:03:32.119Z",
        "totalSpent": 22,
        "latestActivity": "2023-06-14T04:45:55.465Z",
        "point": 9999800,
        "updatedAt": "2023-08-08T06:48:42.938Z",
        "appliedCollectionIds": []
    },
    "discount": {
        "id": "gid://shopify/DiscountCodeNode/1396689076511",
        "code": "JOY-1YOCADBV6JMW"
    }
}
```

### Generate referral link

This method will generate the referral link for the customer by their email. This will only create a new link if the customer matching the email has not created one. If not, it will return the existing referral link.

```javascript
joyInstance.generateLinkReferral(email).then(function(resp){
    console.log(resp)
});
```

Sample response:

```json
{
    "url":"https://inviteee.to/i/a8h3"
}
```

### Update date of birth

Our app stores customer birthdays in the format: DD/MM. You can update that on behalf of the logged-in user.

```javascript
joyInstance.updateDOB(month, day).then(function(resp){
    console.log(resp)
});
```

Sample response:

```json
{status: true}
```

### Revoke coupon

This API will enable a coupon revocation action for coupons at your customer's end.

```javascript
joyInstance.revokeCoupon(rewardId).then(function(resp){
    console.log(resp)
});
```

Sample response

```json
{status: true}
```
