> For the complete documentation index, see [llms.txt](https://docs.conscent.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.conscent.ai/discount-coupon/dynamic-coupon-api-generation.md).

# Dynamic Coupon API Generation:

## Basic Auth:

<mark style="color:green;">`POST`</mark> `{API_URL}/subscription/discount-coupon-template/generate-user-coupon`

Enter[ API-KEY and API-Secret](https://sandbox-client.conscent.in/client/dashboard/Documentation) as username and password respectively.

#### Request Body

| Name                                           | Type             | Description                                          |
| ---------------------------------------------- | ---------------- | ---------------------------------------------------- |
| couponName<mark style="color:red;">\*</mark>   | String           | <p>Unique identifier for the coupon name.</p><p></p> |
| clientId<mark style="color:red;">\*</mark>     | String           | Unique identifier for the client.                    |
| quantity<mark style="color:red;">\*</mark>     | Integer          | Number of coupons to be generated.                   |
| couponCodes <mark style="color:red;">\*</mark> | Array of Strings | Predefined coupon codes provided by the client.      |

{% tabs %}
{% tab title="201: Created Details of the generated coupons including identifiers and metadata are provided in the response." %}
Details of the generated coupons including identifiers and metadata are provided in the response.
{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Example for AUTO\_ALLOCATE :" %}

```json
{
  "couponName": "Test Dynamic Coupon",
  "clientId": "YOUR_CLIENT_ID",
  "quantity": 10
}
```

{% endtab %}

{% tab title="Example for AUTO\_ACCEPT :" %}

```json
{ "couponName": "Test Dynamic Coupon",
 "clientId": "5f92a62013332e0f667794dc", 
"couponCodes": ["TESTDIWALI500", "fdhfuhiufh", "FUNCHRISTMAS"] }
```

{% endtab %}
{% endtabs %}

<details>

<summary><strong>Rules and Constraints:</strong></summary>

Functionality of AUTO\_ALLOCATE and AUTO\_ACCEPT templates are exclusive:&#x20;

**AUTO\_ALLOCATE:** Automatic generation in specified quantity.&#x20;

**AUTO\_ACCEPT:** Generation based on client-provided **couponCodes.**

The quantity parameter is ignored for **AUTO\_ACCEPT,** and **couponCodes** for **AUTO\_ALLOCATE.**&#x20;

**couponCodes** must be unique and follow format/validation rules of the template.&#x20;

**Quantity Limitation:** The quantity of coupons requested in an AUTO\_ALLOCATE template cannot exceed the maximum quantity set for that template in the dashboard during template creation. Attempts to generate coupons beyond this limit will result in an error

</details>

**Error Handling:** Error messages and codes for scenarios like invalid template IDs, missing fields, or invalid coupon codes. Specific errors will be returned if the requested quantity exceeds the template's maximum limit.
