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

# グループの公開

> テスト環境から本番環境に商品グループを公開する

テスト環境から本番環境に商品グループを公開します。UPSERT 動作を使用します -- 商品の公開（初回公開のみ）とは異なり、変更後に再公開できます。

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

**認証：** API Key

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

## リクエストボディ

| フィールド | 型      | 必須  | 説明                                        |
| ----- | ------ | --- | ----------------------------------------- |
| `id`  | string | Yes | グループ ID（UUID フォーマット、テスト環境のグループである必要があります） |

## リクエスト例

<CodeGroup>
  ```typescript SDK theme={"system"}
  await client.subscriptionProductGroups.publish({
    id: "d4e5f6a7-b8c9-0d1e-2f3a-4b5c6d7e8f9a",
  });
  ```

  ```typescript TypeScript (fetch) theme={"system"}
  // Uses callApi() helper from authentication.mdx
  const result = await callApi("POST", "/v1/actions/subscription-product-group/publish-group", {
    id: "d4e5f6a7-b8c9-0d1e-2f3a-4b5c6d7e8f9a",
  });
  console.log(result.data);
  ```

  ```java Java theme={"system"}
  // Uses callApi() helper from authentication.mdx
  String body = """
      {"id":"d4e5f6a7-b8c9-0d1e-2f3a-4b5c6d7e8f9a"}""";

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

  ```python Python theme={"system"}
  # Uses call_api() helper from authentication.mdx
  result = call_api("POST", "/v1/actions/subscription-product-group/publish-group", {
      "id": "d4e5f6a7-b8c9-0d1e-2f3a-4b5c6d7e8f9a",
  })
  print(result["data"])
  ```

  ```go Go theme={"system"}
  // Uses callAPI() helper from authentication.mdx
  body := map[string]interface{}{
      "id": "d4e5f6a7-b8c9-0d1e-2f3a-4b5c6d7e8f9a",
  }
  result, err := callAPI("POST", "/v1/actions/subscription-product-group/publish-group", 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": "d4e5f6a7-b8c9-0d1e-2f3a-4b5c6d7e8f9a"
  });
  let result = call_api("POST", "/v1/actions/subscription-product-group/publish-group", &body).await?;
  println!("{}", result);
  ```

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

  ```cpp C++ theme={"system"}
  // Uses callApi() helper from authentication.mdx
  std::string body = R"({"id":"d4e5f6a7-b8c9-0d1e-2f3a-4b5c6d7e8f9a"})";
  std::string response = callApi("POST", "/v1/actions/subscription-product-group/publish-group", body);
  std::cout << response << std::endl;
  ```

  ```bash cURL theme={"system"}
  MERCHANT_ID="MER_2aUyqjCzEIiEcYMKj7TZtw"
  TIMESTAMP=$(date +%s)
  BODY='{"id":"d4e5f6a7-b8c9-0d1e-2f3a-4b5c6d7e8f9a"}'
  BODY_HASH=$(echo -n "$BODY" | openssl dgst -sha256 -binary | base64 -w 0)
  CANONICAL_REQUEST="POST
  /v1/actions/subscription-product-group/publish-group
  $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-group/publish-group" \
    -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":"d4e5f6a7-b8c9-0d1e-2f3a-4b5c6d7e8f9a"}'
  BODY_HASH=$(echo -n "$BODY" | openssl dgst -sha256 -binary | base64 -w 0)
  CANONICAL_REQUEST="POST
  /v1/actions/subscription-product-group/publish-group
  $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-group/publish-group" \
    --header="Content-Type: application/json" \
    --header="X-Merchant-Id: $MERCHANT_ID" \
    --header="X-Timestamp: $TIMESTAMP" \
    --header="X-Signature: $SIGNATURE" \
    --post-data="$BODY"
  ```
</CodeGroup>

<Note>
  商品の公開とは異なり、グループの公開は**繰り返しの UPSERT 操作**をサポートしています。テストグループを更新し、いつでも本番環境に再公開できます。本番環境のグループは現在のテストグループに合わせて作成または更新されます。
</Note>

## エラー

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

| ステータス | `errors[0].message`                        | 意味                                       | 推奨処理                                     |
| ----- | ------------------------------------------ | ---------------------------------------- | ---------------------------------------- |
| 400   | `Missing required field: id`               | リクエストボディに `id` が含まれない                    | `id` を追加して再送信                            |
| 400   | `Can only publish test environment groups` | 指定されたグループはすでに production（または test 以外）にある | 公開可能なのは test 環境のグループのみ                   |
| 400   | `Cannot publish: product_ids is empty`     | グループにメンバー商品がない                           | `update-group` でグループに 1 つ以上の商品を追加してから再送信 |
| 404   | `Group not found`                          | 指定された `id` のグループが存在しない                   | `id` が自分のストアに属しているか確認                    |
| 500   | `Internal server error`                    | 内部エラーまたは一時的な下流障害                         | 指数バックオフでリトライ（5s 開始、最大 3 回）               |
