# Coupons

## Get all coupons

<mark style="color:blue;">`GET`</mark> `https://plugin.tebex.io/coupons`

Return a paginated list of coupons on your account.

#### Headers

| Name           | Type   | Description                 |
| -------------- | ------ | --------------------------- |
| X-Tebex-Secret | string | The secret key of a server. |

{% tabs %}
{% tab title="200 " %}

```javascript
{
 "pagination": {
        "totalResults": 157,
        "currentPage": 1,
        "lastPage": 7,
        "previous": null,
        "next": "https://plugin.tebex.io/coupons?page=2"
  },
  "data": [
    {
      "id": 2,
      "code": "mycode-123",
      "effective": {
        "type": "cart",
        "packages": [],
        "categories": []
      },
      "discount": {
        "type": "value",
        "percentage": 0,
        "value": 2
      },
      "expire": {
        "redeem_unlimited": "false",
        "expire_never": "true",
        "limit": 0,
        "date": "1901-12-13T20:45:52+0000"
      },
      "basket_type": "single",
      "start_date": "2017-01-01T00:00:00+0000",
      "user_limit": 1,
      "minimum": 5,
      "username": "Notch",
      "note": "Coupon note"
    }
  ]
}
```

{% endtab %}
{% endtabs %}

## Get a coupon

<mark style="color:blue;">`GET`</mark> `https://plugin.tebex.io/coupons/{id}`

Get a coupon by ID.

#### Path Parameters

| Name | Type   | Description    |
| ---- | ------ | -------------- |
| id   | string | The coupon ID. |

#### Headers

| Name           | Type   | Description                 |
| -------------- | ------ | --------------------------- |
| X-Tebex-Secret | string | The secret key of a server. |

{% tabs %}
{% tab title="200 " %}

```javascript
{
  "data": {
    "id": 2,
    "code": "mycode-123",
    "effective": {
      "type": "cart",
      "packages": [],
      "categories": []
    },
    "discount": {
      "type": "value",
      "percentage": 0,
      "value": 2
    },
    "expire": {
      "redeem_unlimited": "true",
      "expire_never": "true",
      "limit": 0,
      "date": "1901-12-13T20:45:52+0000"
    },
    "basket_type": "single",
    "start_date": "2017-01-01T00:00:00+0000",
    "user_limit": 1,
    "minimum": 5,
    "username": "",
    "note": "Coupon note"
  }
}
```

{% endtab %}
{% endtabs %}

## Create a coupon

<mark style="color:green;">`POST`</mark> `https://plugin.tebex.io/coupons`

Create a coupon code.

#### Headers

| Name           | Type   | Description                 |
| -------------- | ------ | --------------------------- |
| X-Tebex-Secret | string | The secret key of a server. |

#### Request Body

| Name                          | Type    | Description                                                                                                |
| ----------------------------- | ------- | ---------------------------------------------------------------------------------------------------------- |
| code                          | string  | The code of the coupon.                                                                                    |
| effective\_on                 | string  | What this coupon should be effective on, either "package", "category" or "cart".                           |
| packages                      | array   | An array of package IDs this coupon should apply to. Only used if effective\_on is "package".              |
| categories                    | array   | An array of category IDs this coupon should apply to. Only used if effective\_on is "category".            |
| discount\_type                | string  | "percentage" or "value".                                                                                   |
| discount\_amount              | integer | The currency amount to discount.                                                                           |
| discount\_percentage          | integer | The percentage amount to be discounted.                                                                    |
| redeem\_unlimited             | boolean | Can the coupon be redeemed an unlimited amount of times.                                                   |
| expire\_never                 | boolean | Should the coupon ignore the expire\_date.                                                                 |
| expire\_limit                 | number  | Only used if redeem\_unlimited is false.                                                                   |
| expire\_date                  | string  | Only used if `expire_never` is `false` - formatted in yyyy-mm-dd.                                          |
| start\_date                   | string  | The start date of the coupon in the format of yyyy-mm-dd.                                                  |
| basket\_type                  | string  | "single", "subscription", or "both".                                                                       |
| minimum                       | number  | Minimum value of basket before the coupon can be redeemed.                                                 |
| discount\_application\_method | number  | 0 = Apply to each package (default), 1 = Apply to basket (before sales), 2 = Apply to basket (after sales) |
| username                      | string  | The username to restrict the coupon to.                                                                    |
| note                          | string  | The note to store against the coupon.                                                                      |

{% tabs %}
{% tab title="200 " %}

```javascript
{
  "data": {
    "id": 3,
    "code": "mycode-123",
    "effective": {
      "type": "cart",
      "packages": [],
      "categories": []
    },
    "discount": {
      "type": "value",
      "percentage": 0,
      "value": 2
    },
    "expire": {
      "redeem_unlimited": "false",
      "expire_never": "true",
      "limit": 0,
      "date": "-0001-11-30T00:00:00+0000"
    },
    "basket_type": "single",
    "start_date": "2017-01-01T00:00:00+0000",
    "user_limit": 1,
    "minimum": 5,
    "discount_application_method" : 0,
    "username": "Notch",
    "note": "Coupon note"
  }
}
```

{% endtab %}
{% endtabs %}

## Delete a coupon

<mark style="color:red;">`DELETE`</mark> `https://plugin.tebex.io/coupons/{id}`

Delete a coupon.

#### Path Parameters

| Name | Type   | Description           |
| ---- | ------ | --------------------- |
| id   | string | The ID of the coupon. |

#### Headers

| Name           | Type   | Description                 |
| -------------- | ------ | --------------------------- |
| X-Tebex-Secret | string | The secret key of a server. |

{% tabs %}
{% tab title="204 " %}

```
```

{% endtab %}
{% endtabs %}
