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

# Update Coupon

> Rename a coupon

Rename a coupon. `name` is the only field that can change: the code, discount, duration, expiry and limits are fixed once the coupon is created. To change them, create a new coupon and deactivate the old one.

```
POST /v1/actions/coupon/update-coupon
```

**Authentication:** API Key

## Request Body

| Field | Type | Required | Description |
| - | - | - | - |
| `id` | string | Yes | Coupon ID (Short ID format `CPN_xxx`) |
| `name` | string | Yes | New internal name (max 64 chars). Buyers do not see it |

Any other field in the body is ignored. Coupons in any status except `pending` can be renamed, including `inactive` and `failed` ones.

## Example Request

```typescript SDK theme={"system"}
const { coupon } = await client.coupons.update({
  id: "CPN_5dXBtmF2HLlHfbPNm0Wcnz",
  name: "Black Friday 20% off (extended)",
});
```

```bash cURL theme={"system"}
MERCHANT_ID="MER_2aUyqjCzEIiEcYMKj7TZtw"
TIMESTAMP=$(date +%s)
BODY='{"id":"CPN_5dXBtmF2HLlHfbPNm0Wcnz","name":"Black Friday 20% off (extended)"}'
BODY_HASH=$(echo -n "$BODY" | openssl dgst -sha256 -binary | base64 | tr -d '\n')
CANONICAL_REQUEST="POST
/v1/actions/coupon/update-coupon
$TIMESTAMP
$BODY_HASH"

SIGNATURE=$(echo -n "$CANONICAL_REQUEST" | openssl dgst -sha256 -sign private_key.pem | base64 | tr -d '\n')

curl -X POST "https://api.waffo.ai/v1/actions/coupon/update-coupon" \
  -H "Content-Type: application/json" \
  -H "X-Merchant-Id: $MERCHANT_ID" \
  -H "X-Timestamp: $TIMESTAMP" \
  -H "X-Signature: $SIGNATURE" \
  -d "$BODY"
```

```python Python theme={"system"}
import hashlib, time, base64, json, requests
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import padding

merchant_id = "MER_2aUyqjCzEIiEcYMKj7TZtw"
timestamp = str(int(time.time()))
body = {
    "id": "CPN_5dXBtmF2HLlHfbPNm0Wcnz",
    "name": "Black Friday 20% off (extended)",
}

body_json = json.dumps(body, separators=(",", ":"))
body_hash = base64.b64encode(hashlib.sha256(body_json.encode()).digest()).decode()
path = "/v1/actions/coupon/update-coupon"
canonical = f"POST\n{path}\n{timestamp}\n{body_hash}"

with open("private_key.pem", "rb") as f:
    private_key = serialization.load_pem_private_key(f.read(), password=None)

signature = base64.b64encode(
    private_key.sign(canonical.encode(), padding.PKCS1v15(), hashes.SHA256())
).decode()

resp = requests.post(
    f"https://api.waffo.ai{path}",
    headers={
        "Content-Type": "application/json",
        "X-Merchant-Id": merchant_id,
        "X-Timestamp": timestamp,
        "X-Signature": signature,
    },
    data=body_json,
)
print(resp.json())
```

## Success Response (200)

```json theme={"system"}
{
  "data": {
    "coupon": {
      "id": "CPN_5dXBtmF2HLlHfbPNm0Wcnz",
      "storeId": "STO_2aUyqjCzEIiEcYMKj7TZtw",
      "name": "Black Friday 20% off (extended)",
      "code": "BF2026",
      "status": "active",
      "discountType": "percentage",
      "percentOff": 20,
      "amountOff": null,
      "duration": "repeating",
      "durationInPeriods": 3,
      "productIds": [],
      "maxRedemptions": 1000,
      "redeemBy": "2026-12-01T00:00:00.000Z",
      "createdAt": "2026-11-01T08:00:00.000Z",
      "updatedAt": "2026-11-20T09:15:00.000Z"
    }
  }
}
```

## Response Fields

Same as [Create Coupon response](https://docs.waffo.ai/api-reference/endpoints/coupons/create-coupon.md), without `promotionCodes`.

## Errors

> **Retry policy:** Never retry 4xx — fix the request and resubmit. Retry 5xx with exponential backoff (start 5s, max 3 attempts).

| Status | `errors[0].message` | What it means | Recommended handling |
| - | - | - | - |
| 400 | `Missing or invalid header: x-context-environment` | Environment header is missing or not `test` / `prod` | Set `X-Environment` to `test` or `prod` |
| 400 | `Invalid JSON body` | The body is not valid JSON | Fix the body, resubmit |
| 400 | `Missing required field: id` / `Missing required field: name` | A required field was omitted | Add the missing field, resubmit |
| 400 | `name must not exceed 64 characters` | `name` is too long | Shorten `name`, resubmit |
| 400 | `Expected format: CPN_xxx, got "X"` | `id` is not a valid Short ID | Use a `CPN_` prefixed Short ID |
| 401 | `Authentication required` | Authentication failed | Verify API key, timestamp, and signature |
| 404 | `Coupon not found` | The coupon does not exist, belongs to another merchant, or is in the other environment | Verify the `id` and the environment of your API key |
| 409 | `Coupon is not active (status: pending)` | The coupon is `pending`: its Create Coupon request is still running, or was interrupted and the coupon has not been cleaned up yet | Wait for the Create Coupon request to finish, then retry |
| 500 | `Internal server error` | Unexpected server-side failure | Retry with exponential backoff (start 5s, max 3 attempts) |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.