> ## Documentation Index
> Fetch the complete documentation index at: https://docs.launchmystore.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Update Discount

> Update an existing discount code

# Update Discount

Updates an existing discount code. Only provided fields will be updated.

## Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X PUT "https://api.launchmystore.io/api/v1/discounts/disc_abc123.json" \
    -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "usage_limit": 1000,
      "ends_at": "2024-09-30T23:59:59Z"
    }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.launchmystore.io/api/v1/discounts/disc_abc123.json', {
    method: 'PUT',
    headers: {
      'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      usage_limit: 1000,
      ends_at: '2024-09-30T23:59:59Z'
    })
  });
  ```
</CodeGroup>

## Path Parameters

<ParamField path="id" type="string" required>
  The unique discount ID to update
</ParamField>

## Body Parameters

All parameters are optional. Only provided fields will be updated. Any field
not listed below is ignored.

<ParamField body="code" type="string">
  Discount code (changing code affects any saved links)
</ParamField>

<ParamField body="type" type="string">
  Discount type: `percentage`, `fixed_amount`, `free_shipping`, `buy_x_get_y`
</ParamField>

<ParamField body="value" type="number">
  Discount value (percentage or fixed amount). Must be `>= 0`.
</ParamField>

<ParamField body="applies_to" type="string">
  What the discount applies to: `all`, `products`, `collections`
</ParamField>

<ParamField body="product_ids" type="array">
  Product IDs (when `applies_to` is `products`)
</ParamField>

<ParamField body="collection_ids" type="array">
  Collection IDs (when `applies_to` is `collections`)
</ParamField>

<ParamField body="minimum_amount" type="number">
  Minimum order amount required for the discount to apply
</ParamField>

<ParamField body="usage_limit" type="integer">
  Maximum total uses. Must be `>= 1`.
</ParamField>

<ParamField body="once_per_customer" type="boolean">
  Limit to one use per customer
</ParamField>

<ParamField body="starts_at" type="string">
  Start date (ISO 8601)
</ParamField>

<ParamField body="ends_at" type="string">
  End date (ISO 8601)
</ParamField>

<ParamField body="status" type="string">
  Discount status: `active`, `expired`, `scheduled`, `disabled`
</ParamField>

## Response

Returns the standard response envelope with the updated discount row under
`data.discount`.

<ResponseField name="status" type="integer">
  HTTP status code (e.g. `200`)
</ResponseField>

<ResponseField name="state" type="string">
  Response state: `success` or `error`
</ResponseField>

<ResponseField name="message" type="string">
  Human-readable message (`null` on success)
</ResponseField>

<ResponseField name="data.discount" type="object">
  The updated discount object
</ResponseField>

## Example Response

```json theme={null}
{
  "status": 200,
  "state": "success",
  "message": null,
  "data": {
    "discount": {
      "couponId": "f73049dc-b4d4-4f85-99c2-681a5e351a8a",
      "code": "SUMMER20",
      "type": "Percentage",
      "status": "Active",
      "discountPercentage": 20,
      "discountAmount": null,
      "minOrderTotal": 50,
      "totalCoupons": 1000,
      "usedCount": 145,
      "usesPerCustomer": 1,
      "applyOnProducts": [],
      "startDate": "2024-06-01T00:00:00Z",
      "endDate": "2024-09-30T23:59:59Z",
      "createdAt": "2024-05-15T10:00:00Z",
      "updatedAt": "2024-07-01T14:30:00Z"
    }
  },
  "count": null,
  "pagination": null
}
```

## Notes

* Setting `status` to `disabled` (or any value other than `active`) deactivates
  the discount; `active` reactivates it.
* Changing the `code` will affect any shared links or saved customer carts.
* Usage count cannot be modified directly.

## Error Response

Errors return the same envelope with an `error` state. A missing discount
returns `404`:

```json theme={null}
{
  "status": 404,
  "state": "error",
  "message": "Discount not found",
  "data": null
}
```
