# Create discount code

`POST https://rcur.app/api/v2/discounts`

## Request body

Discount code data

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `code` | string | yes | Letters, digits, - and _; stored in capitals |
| `name` | string | no | Internal name |
| `type` | string | yes | One of: `percentage`, `fixed`. |
| `value` | number | yes | A percentage (at most 100) or an amount |
| `currency` | string | no | Required for a fixed amount |
| `duration` | string | yes | One of: `once`, `repeating`, `forever`. |
| `duration_periods` | integer | no | Required for repeating |
| `all_links` | boolean | no | Default true |
| `links` | array of strings | no | Payment link ids, required when all_links is false |
| `max_redemptions` | integer | no |  |
| `once_per_customer` | boolean | no |  |
| `starts_at` | string | no |  |
| `expires_at` | string | no |  |
| `is_active` | boolean | no | Default true |

## Example request

```bash
curl -X POST https://rcur.app/api/v2/discounts \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
  "code": "SUMMER25",
  "name": "Summer campaign",
  "type": "percentage",
  "value": 25,
  "currency": "EUR",
  "duration": "repeating",
  "duration_periods": 3,
  "all_links": false,
  "links": [
    "xY1zA2bC3d"
  ],
  "max_redemptions": 100,
  "once_per_customer": true,
  "starts_at": "2026-06-01",
  "expires_at": "2026-08-31",
  "is_active": true
}'
```

## Responses

### 201 Discount code created

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | yes |  |
| `code` | string | yes |  |
| `name` | string | no |  |
| `type` | string | yes | One of: `percentage`, `fixed`. |
| `value` | string | yes | A percentage, or an amount in the currency of the code |
| `currency` | string | no | Only for a fixed amount |
| `duration` | string | yes | How many payments of a subscription get the discount: the first, the first duration_periods, or every payment One of: `once`, `repeating`, `forever`. |
| `duration_periods` | integer | no |  |
| `all_links` | boolean | yes | Valid for every payment link, or only for the links in links |
| `links` | array of strings | no | Ids of the payment links the code is limited to |
| `max_redemptions` | integer | no | How often the code can be used in total, by all customers together |
| `times_redeemed` | integer | no |  |
| `once_per_customer` | boolean | no |  |
| `starts_at` | string | no |  |
| `expires_at` | string | no |  |
| `is_active` | boolean | yes |  |
| `status` | string | yes | One of: `active`, `inactive`, `scheduled`, `expired`, `used_up`. |
| `created_at` | string | yes |  |

```json
{
    "id": "aB3dE5fG7h",
    "code": "SUMMER25",
    "name": "Summer campaign",
    "type": "percentage",
    "value": "25.00",
    "currency": "EUR",
    "duration": "repeating",
    "duration_periods": 3,
    "all_links": false,
    "links": [
        "xY1zA2bC3d"
    ],
    "max_redemptions": 100,
    "times_redeemed": 12,
    "once_per_customer": true,
    "starts_at": "2026-06-01",
    "expires_at": "2026-08-31",
    "is_active": true,
    "status": "active",
    "created_at": "2026-05-20 10:00:00"
}
```

### 422 Validation error

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `status` | integer | yes |  |
| `error` | string | yes |  |
| `fields` | object | no |  |

```json
{
    "status": 422,
    "error": "Could not process request. Some fields contain invalid data",
    "fields": {
        "email": [
            "The email field is required."
        ]
    }
}
```
