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

# クーポンの更新

> クーポン名を変更する

クーポン名を変更します。変更できるフィールドは `name` のみです。コード、割引内容、適用期間、有効期限、使用回数の上限は作成後に変更できません。変更したい場合は、新しいクーポンを作成し、古いクーポンを無効化してください。

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

**認証：** API Key

## リクエストボディ

| フィールド | 型 | 必須 | 説明 |
| - | - | - | - |
| `id` | string | はい | クーポン ID（Short ID 形式 `CPN_xxx`） |
| `name` | string | はい | 新しい内部用の名前（最大 64 文字）。購入者には表示されません |

ボディ内のその他のフィールドは無視されます。`pending` 以外のどのステータス（`inactive`、`failed` を含む）のクーポンでも名前を変更できます。

## リクエスト例

```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())
```

## 成功レスポンス (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"
    }
  }
}
```

## レスポンスフィールド

[クーポンの作成のレスポンス](https://docs.waffo.ai/ja/api-reference/endpoints/coupons/create-coupon.md)と同じです（`promotionCodes` を除く）。

## エラー

> **リトライポリシー**：4xx は一切リトライしない — リクエストを修正してから再送信。5xx は指数バックオフでリトライ（5s 開始、最大 3 回）。

| ステータス | `errors[0].message` | 意味 | 推奨処理 |
| - | - | - | - |
| 400 | `Missing or invalid header: x-context-environment` | 環境 header が欠落、または `test` / `prod` ではない | `X-Environment` を `test` または `prod` に設定 |
| 400 | `Invalid JSON body` | ボディが正しい JSON ではない | ボディを修正して再送信 |
| 400 | `Missing required field: id` / `Missing required field: name` | 必須フィールド欠落 | フィールドを追加して再送信 |
| 400 | `name must not exceed 64 characters` | `name` が長すぎる | `name` を短くして再送信 |
| 400 | `Expected format: CPN_xxx, got "X"` | `id` が正しい Short ID ではない | `CPN_` 接頭辞付きの Short ID を使用 |
| 401 | `Authentication required` | 認証失敗 | API Key、タイムスタンプ、署名を確認 |
| 404 | `Coupon not found` | クーポンが存在しない、他のマーチャントに属する、または別の環境にある | `id` と API Key の環境を確認 |
| 409 | `Coupon is not active (status: pending)` | クーポンが `pending`：クーポン作成のリクエストがまだ処理中、または中断されてまだクリーンアップされていない | クーポン作成のリクエストが終わってからリトライ |
| 500 | `Internal server error` | サーバ側の予期しない障害 | 指数バックオフでリトライ（5s 開始、最大 3 回） |


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