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

# 商品の公開

> テスト環境から本番環境にサブスクリプション商品を公開する

テスト環境から本番環境にサブスクリプション商品を公開します。これは一方向の初回公開のみの操作です。

```
POST /v1/actions/subscription-product/publish-product
```

**認証：** API Key

<Warning>
  このエンドポイントには `X-Environment` ヘッダーを含め**ないでください**。公開は常にテストから本番環境への一方向です。
</Warning>

## リクエストボディ

| フィールド | 型      | 必須  | 説明                       |
| ----- | ------ | --- | ------------------------ |
| `id`  | string | Yes | 商品 ID（`PROD_xxx` フォーマット） |

## リクエスト例

<CodeGroup>
  ```typescript SDK theme={"system"}
  await client.subscriptionProducts.publish({
    id: "PROD_3F7H2J5L8N1Q4S6U",
  });
  ```

  ```typescript TypeScript (fetch) theme={"system"}
  // Uses callApi() helper from authentication.mdx
  const result = await callApi("POST", "/v1/actions/subscription-product/publish-product", {
    id: "PROD_3F7H2J5L8N1Q4S6U",
  });
  console.log(result.data);
  ```

  ```java Java theme={"system"}
  // Uses callApi() helper from authentication.mdx
  String body = """
      {"id":"PROD_3F7H2J5L8N1Q4S6U"}""";

  String response = callApi("POST", "/v1/actions/subscription-product/publish-product", body);
  System.out.println(response);
  ```

  ```python Python theme={"system"}
  # Uses call_api() helper from authentication.mdx
  result = call_api("POST", "/v1/actions/subscription-product/publish-product", {
      "id": "PROD_3F7H2J5L8N1Q4S6U",
  })
  print(result["data"])
  ```

  ```go Go theme={"system"}
  // Uses callAPI() helper from authentication.mdx
  body := map[string]interface{}{
      "id": "PROD_3F7H2J5L8N1Q4S6U",
  }
  result, err := callAPI("POST", "/v1/actions/subscription-product/publish-product", body)
  if err != nil {
      log.Fatal(err)
  }
  fmt.Println(string(result))
  ```

  ```rust Rust theme={"system"}
  // Uses call_api() helper from authentication.mdx
  let body = serde_json::json!({
      "id": "PROD_3F7H2J5L8N1Q4S6U"
  });
  let result = call_api("POST", "/v1/actions/subscription-product/publish-product", &body).await?;
  println!("{}", result);
  ```

  ```c C theme={"system"}
  /* Uses call_api() helper from authentication.mdx */
  const char *body = "{\"id\":\"PROD_3F7H2J5L8N1Q4S6U\"}";
  char *response = call_api("POST", "/v1/actions/subscription-product/publish-product", body);
  printf("%s\n", response);
  free(response);
  ```

  ```cpp C++ theme={"system"}
  // Uses callApi() helper from authentication.mdx
  std::string body = R"({"id":"PROD_3F7H2J5L8N1Q4S6U"})";
  std::string response = callApi("POST", "/v1/actions/subscription-product/publish-product", body);
  std::cout << response << std::endl;
  ```

  ```bash cURL theme={"system"}
  MERCHANT_ID="MER_2aUyqjCzEIiEcYMKj7TZtw"
  TIMESTAMP=$(date +%s)
  BODY='{"id":"PROD_3F7H2J5L8N1Q4S6U"}'
  BODY_HASH=$(echo -n "$BODY" | openssl dgst -sha256 -binary | base64 -w 0)
  CANONICAL_REQUEST="POST
  /v1/actions/subscription-product/publish-product
  $TIMESTAMP
  $BODY_HASH"

  SIGNATURE=$(echo -n "$CANONICAL_REQUEST" | openssl dgst -sha256 -sign private_key.pem | base64 -w 0)

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

  ```bash wget theme={"system"}
  MERCHANT_ID="MER_2aUyqjCzEIiEcYMKj7TZtw"
  TIMESTAMP=$(date +%s)
  BODY='{"id":"PROD_3F7H2J5L8N1Q4S6U"}'
  BODY_HASH=$(echo -n "$BODY" | openssl dgst -sha256 -binary | base64 -w 0)
  CANONICAL_REQUEST="POST
  /v1/actions/subscription-product/publish-product
  $TIMESTAMP
  $BODY_HASH"

  SIGNATURE=$(echo -n "$CANONICAL_REQUEST" | openssl dgst -sha256 -sign private_key.pem | base64 -w 0)

  wget -qO- "https://api.waffo.ai/v1/actions/subscription-product/publish-product" \
    --header="Content-Type: application/json" \
    --header="X-Merchant-Id: $MERCHANT_ID" \
    --header="X-Timestamp: $TIMESTAMP" \
    --header="X-Signature: $SIGNATURE" \
    --post-data="$BODY"
  ```
</CodeGroup>

## 成功レスポンス (200)

```json theme={"system"}
{
  "data": {
    "product": {
      "id": "PROD_3F7H2J5L8N1Q4S6U",
      "storeId": "STO_2D5F8G3H1K4M6N9P",
      "name": "Pro Plan",
      "description": "Full access to all Pro features.",
      "billingPeriod": "monthly",
      "prices": {
        "USD": { "amount": "29.00", "taxCategory": "saas" },
        "EUR": { "amount": "27.00", "taxCategory": "saas" }
      },
      "media": [],
      "successUrl": "https://example.com/welcome",
      "metadata": { "trialDays": 14 },
      "status": "active",
      "createdAt": "2026-03-30T10:30:00.000Z",
      "updatedAt": "2026-03-30T12:00:00.000Z"
    }
  }
}
```

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

[サブスクリプション商品の作成レスポンス](/api-reference/endpoints/subscription-products/create-product#response-fields)と同じです。

<Note>
  **初回公開のみ**サポートされています。商品に本番バージョンが存在する場合、このエンドポイントはエラーを返します。公開済みの商品を更新するには、本番環境で[商品の更新](/api-reference/endpoints/subscription-products/update-product)エンドポイントを使用してください。
</Note>

## エラー

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

| ステータス | `errors[0].message`                              | 意味                                   | 推奨処理                                                     |
| ----- | ------------------------------------------------ | ------------------------------------ | -------------------------------------------------------- |
| 400   | `Missing header: x-context-merchant-id`          | マーチャントコンテキスト header が転送されていない        | SDK 設定を修正                                                |
| 400   | `Missing required field: id`                     | リクエストボディに `id` が含まれない                | `id` を追加して再送信                                            |
| 400   | `Expected format: PROD_xxx, got "X"`             | `id` が正しい Short ID ではない              | `PROD_` 接頭辞付きの Short ID を使用                              |
| 400   | `No test version found`                          | この商品は test 環境に公開可能なバージョンが存在しない       | 先に Update Product / Update Status で test バージョンを作成・アクティブ化 |
| 400   | `Test version is not active`                     | test バージョンは存在するが状態が `inactive`       | 先に Update Status で test バージョンをアクティブ化してから公開               |
| 400   | `Already published to production`                | 商品に既に prod バージョンが存在（publish は初回公開のみ） | prod 環境で Update Product を呼び出す                            |
| 401   | `Unauthorized`                                   | 認証失敗                                 | API Key、タイムスタンプ、署名を確認                                    |
| 404   | `Product not found` / `Source version not found` | product ID が存在しない（またはソースバージョン欠落）     | product ID を確認                                           |
| 500   | `Internal server error`                          | 一時的な下流障害                             | 指数バックオフでリトライ（5s 開始、最大 3 回）                               |
