# 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.conscent.ai/discount-coupon/dynamic-coupon-api-generation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
