# Update Coupon - Modify Discount Code Settings via API

> Update coupon settings including discount amount, usage limits, and expiration date via API.

Source: https://docs.botsubscription.com/api/coupons/update/

Modify an existing discount coupon's settings. Change the discount amount, update targeting rules, toggle auto-apply, or archive the coupon to stop new redemptions. Only the fields you include in the request body are updated.

<ApiEndpoint method="PATCH" endpoint="/v2/projects/{project_id}/coupons/{coupon_id}" />

<ApiAuthorization type="Bearer API Key" />

**API key access:** Unrestricted project API key required. Restricted keys cannot call this endpoint.

<ApiSection title="Path Parameters">
  <ApiParameter name="project_id" type="string" required description="The unique identifier of the project." />
  <ApiParameter name="coupon_id" type="string" required description="The unique identifier of the coupon." />
</ApiSection>

<ApiSection title="Request Body">
  <ApiParameter name="display_name" type="string" description="Display name for the coupon." />
  <ApiParameter name="description" type="string" description="A description of the coupon." />
  <ApiParameter name="percentage" type="string|number|null" description="Discount percentage, strictly greater than 0 and at most 100. Prefer an exact decimal string; JSON numbers must satisfy numeric precision limits." />
  <ApiParameter name="amount" type="string|number|null" description="Fixed discount amount as a decimal string (for fixed type coupons)." />
  <ApiParameter name="min_spend_amount" type="string | number | null" description="Inclusive minimum checkout amount. Use an unsigned decimal string or nonnegative number; null clears this bound and its currency." />
  <ApiParameter name="min_spend_currency" type="string | null" description="Minimum-spend currency: 3 to 9 uppercase ASCII letters or digits. A currency-only change preserves the existing amount; null clears the bound." />
  <ApiParameter name="max_spend_amount" type="string | number | null" description="Inclusive maximum checkout amount. Use an unsigned decimal string or nonnegative number; null clears this bound and its currency." />
  <ApiParameter name="max_spend_currency" type="string | null" description="Maximum-spend currency: 3 to 9 uppercase ASCII letters or digits. A currency-only change preserves the existing amount; null clears the bound." />
  <ApiParameter name="auto_apply" type="boolean" description="Whether to auto-apply this coupon." />
  <ApiParameter name="status" type="string" description="Coupon status: active or archived." />
  <ApiParameter name="invitee_mode" type="string" description="Who can use: all, inviteesOnly, nonInvitees." />
  <ApiParameter name="renewal_constraint" type="string" description="When applicable: any, renewalOnly, churnedOnly." />
  <ApiParameter name="plan_scope" type="string" description="Which plans: all, include, exclude (plan_ids required when include or exclude)." />
  <ApiParameter name="starts_at" type="number | string | null" description="Validity start: 13-digit Unix milliseconds as a number or digit string. Send null to clear the bound. ISO dates and seconds are not accepted." />
  <ApiParameter name="ends_at" type="number | string | null" description="Validity end: 13-digit Unix milliseconds as a number or digit string. Send null to clear the bound. ISO dates and seconds are not accepted." />
  <ApiParameter name="metadata" type="object" description="Custom metadata for the coupon." />
</ApiSection>

Numeric coupon values follow the [decimal input contract](https://docs.botsubscription.com/api/overview/#decimal-amounts). A nullable value may be cleared only when the resulting coupon still satisfies its type requirements.

Omitted spend fields preserve the existing configuration. A currency-only change keeps that bound's stored amount. Clear a bound by setting its amount **or its currency** to `null`, for example `{"min_spend_currency":null}`.

Changing any spend field validates the resulting stored range: each amount needs a currency, both currencies must match, and the minimum must be no greater than the maximum. Equal bounds are allowed. An invalid merged range returns `422 VALIDATION_ERROR` without applying the update. Send an amount and its currency together when introducing a bound.

Use the [coupon creation rules](https://docs.botsubscription.com/api/coupons/create/) for decimal-string syntax and inclusive spend limits.

<Note>
Response examples use the [UTC ISO date format](https://docs.botsubscription.com/api/overview/#utc-iso-response-dates).
</Note>

<ApiSamplePane>

<ApiRequestSample title="Request">

```bash
curl -X PATCH "https://api.botsubscription.com/v2/projects/f47ac10b-58cc-4372-a567-0e02b2c3d479/coupons/coupon_abc123" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "percentage": "25",
    "ends_at": 1727740799000
  }'
```

```javascript
const project_id = 'f47ac10b-58cc-4372-a567-0e02b2c3d479';
const coupon_id = 'coupon_abc123';
const response = await fetch(`https://api.botsubscription.com/v2/projects/${project_id}/coupons/${coupon_id}`, {
  method: 'PATCH',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    percentage: '25',
    ends_at: 1727740799000
  })
});
const data = await response.json();
```

```python
import requests

project_id = 'f47ac10b-58cc-4372-a567-0e02b2c3d479'
coupon_id = 'coupon_abc123'
response = requests.patch(
    f'https://api.botsubscription.com/v2/projects/{project_id}/coupons/{coupon_id}',
    headers={
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
    },
    json={
        'percentage': '25',
        'ends_at': 1727740799000
    }
)
data = response.json()
```

```php
$project_id = 'f47ac10b-58cc-4372-a567-0e02b2c3d479';
$coupon_id = 'coupon_abc123';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.botsubscription.com/v2/projects/{$project_id}/coupons/{$coupon_id}");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer YOUR_API_KEY',
    'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    'percentage' => '25',
    'ends_at' => 1727740799000
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
```

</ApiRequestSample>

<ApiResponseTabs>
  <ApiResponse status={200} description="Coupon updated">

```json
{
  "ok": true,
  "request_id": "11111111-1111-1111-1111-111111111111",
  "method": "PATCH",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/coupons/11111111-1111-1111-1111-111111111111",
  "code": 200,
  "data": {
    "coupon_id": "11111111-1111-1111-1111-111111111111",
    "code": "SUMMER2024",
    "display_name": "Summer Sale",
    "description": "Updated summer discount",
    "coupon_type": "percentage",
    "percentage": "25",
    "auto_apply": false,
    "status": "active",
    "total_redemptions": 45,
    "total_reservations": 0,
    "invitee_mode": "all",
    "renewal_constraint": "any",
    "payment_count_comparator": "any",
    "lifetime_revenue_comparator": "any",
    "plan_scope": "all",
    "starts_at": "2024-06-01T00:00:00.000Z",
    "ends_at": "2024-09-30T23:59:59.000Z",
    "created_at": "2024-05-15T10:00:00.000Z",
    "metadata": {},
    "min_spend_amount": "1",
    "min_spend_currency": "USD",
    "max_spend_amount": "100",
    "max_spend_currency": "USD"
  }
}
```

  </ApiResponse>
  <ApiResponse status={404} description="Coupon not found">

```json
{
  "ok": false,
  "request_id": "11111111-1111-1111-1111-111111111111",
  "method": "PATCH",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/coupons/11111111-1111-1111-1111-111111111111",
  "code": 404,
  "error": {
    "error_code": "NOT_FOUND",
    "message": "Requested resource could not be found"
  }
}
```

  </ApiResponse>
  <ApiResponse status={401} description="Invalid or expired API key">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "PATCH",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/coupons/cccccccc-cccc-4ccc-8ccc-cccccccccccc",
  "code": 401,
  "error": {
    "message": "Invalid or expired authentication token.",
    "error_code": "UNAUTHORIZED"
  }
}
```

  </ApiResponse>
  <ApiResponse status={422} description="Updated spend currencies do not match">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "PATCH",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/coupons/cccccccc-cccc-4ccc-8ccc-cccccccccccc",
  "code": 422,
  "error": {
    "message": "Minimum and maximum spend must use the same currency.",
    "error_code": "VALIDATION_ERROR"
  }
}
```

  </ApiResponse>
  <ApiResponse status={422} description="Updated minimum exceeds the stored maximum">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "PATCH",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/coupons/cccccccc-cccc-4ccc-8ccc-cccccccccccc",
  "code": 422,
  "error": {
    "message": "Maximum spend must be greater than minimum spend.",
    "error_code": "VALIDATION_ERROR"
  }
}
```

  </ApiResponse>
  <ApiResponse status={422} description="Percentage exceeds the exact upper limit">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "PATCH",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/coupons/cccccccc-cccc-4ccc-8ccc-cccccccccccc",
  "code": 422,
  "errors": [
    {
      "message": "body: percentage Percentage must be greater than 0 and at most 100.",
      "error_code": "VALIDATION_ERROR"
    }
  ]
}
```

  </ApiResponse>
<ApiResponse status={200} description="Fixed-amount coupon">

```json
{
  "ok": true,
  "request_id": "11111111-1111-1111-1111-111111111111",
  "method": "PATCH",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/coupons/11111111-1111-1111-1111-111111111111",
  "code": 200,
  "data": {
    "coupon_id": "11111111-1111-1111-1111-111111111111",
    "code": "FIXED10",
    "display_name": "Ten dollar discount",
    "description": "Updated summer discount",
    "coupon_type": "fixed",
    "auto_apply": false,
    "status": "active",
    "total_redemptions": 45,
    "total_reservations": 0,
    "invitee_mode": "all",
    "renewal_constraint": "any",
    "payment_count_comparator": "any",
    "lifetime_revenue_comparator": "any",
    "plan_scope": "all",
    "starts_at": "2024-06-01T00:00:00.000Z",
    "ends_at": "2024-09-30T23:59:59.000Z",
    "created_at": "2024-05-15T10:00:00.000Z",
    "metadata": {},
    "min_spend_amount": "1",
    "min_spend_currency": "USD",
    "max_spend_amount": "100",
    "max_spend_currency": "USD",
    "amount": "10",
    "currency": "USD"
  }
}
```

</ApiResponse>
</ApiResponseTabs>

</ApiSamplePane>
