> ## 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/onetime-product/publish-product
```

**認証：** API Key

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

## リクエストボディ

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

## リクエスト例

<CodeGroup>
  ```typescript SDK theme={"system"}
  const { product } = await client.onetimeProducts.publish({
    id: "PROD_3kF9mNpQrStUvWxYz1A2bC",
  });
  ```

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

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

  String response = callApi("POST", "/v1/actions/onetime-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/onetime-product/publish-product", {
      "id": "PROD_3kF9mNpQrStUvWxYz1A2bC",
  })
  print(result["data"]["product"]["status"])  # => "active"
  ```

  ```go Go theme={"system"}
  // Uses callAPI() helper from authentication.mdx
  body := map[string]interface{}{
      "id": "PROD_3kF9mNpQrStUvWxYz1A2bC",
  }
  result, err := callAPI("POST", "/v1/actions/onetime-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_3kF9mNpQrStUvWxYz1A2bC"
  });
  let result = call_api("POST", "/v1/actions/onetime-product/publish-product", &body).await?;
  println!("{}", result);
  ```

  ```c C theme={"system"}
  /* Uses call_api() helper from authentication.mdx */
  const char *body = "{\"id\":\"PROD_3kF9mNpQrStUvWxYz1A2bC\"}";
  char *response = call_api("POST", "/v1/actions/onetime-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_3kF9mNpQrStUvWxYz1A2bC"})";
  std::string response = callApi("POST", "/v1/actions/onetime-product/publish-product", body);
  std::cout << response << std::endl;
  ```

  ```bash cURL theme={"system"}
  MERCHANT_ID="MER_2aUyqjCzEIiEcYMKj7TZtw"
  TIMESTAMP=$(date +%s)
  BODY='{"id":"PROD_3kF9mNpQrStUvWxYz1A2bC"}'
  BODY_HASH=$(echo -n "$BODY" | openssl dgst -sha256 -binary | base64 -w 0)
  CANONICAL_REQUEST="POST
  /v1/actions/onetime-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/onetime-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_3kF9mNpQrStUvWxYz1A2bC"}'
  BODY_HASH=$(echo -n "$BODY" | openssl dgst -sha256 -binary | base64 -w 0)
  CANONICAL_REQUEST="POST
  /v1/actions/onetime-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/onetime-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_3kF9mNpQrStUvWxYz1A2bC",
      "storeId": "STO_2aUyqjCzEIiEcYMKj7TZtw",
      "name": "Premium Template Pack",
      "description": "50 premium design templates for your next project.",
      "prices": {
        "USD": { "amount": "49.00", "taxCategory": "digital_goods" },
        "EUR": { "amount": "45.00", "taxCategory": "digital_goods" }
      },
      "media": [
        { "type": "image", "url": "https://example.com/templates-preview.png", "alt": "Template preview" }
      ],
      "successUrl": "https://example.com/thank-you",
      "metadata": { "category": "design", "fileCount": "50" },
      "status": "active",
      "createdAt": "2026-01-15T10:30:00.000Z",
      "updatedAt": "2026-01-15T12:00:00.000Z"
    }
  }
}
```

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

[商品の作成レスポンス](/api-reference/endpoints/onetime-products/create-product#response-fields)と同じです。

<Note>
  **初回公開のみ**サポートされています。商品に本番バージョンが存在する場合、このエンドポイントは同じ商品に再度使用できません。初回公開後に本番バージョンを更新するには、`X-Environment: prod` ヘッダーを付けて[商品の更新](/api-reference/endpoints/onetime-products/update-product)エンドポイントを使用してください。
</Note>

## エラー

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

| ステータス | `errors[0].message`               | 意味                            | 推奨処理                                                                                                             |
| ----- | --------------------------------- | ----------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| 400   | `Missing required field: id`      | `id` が指定されていません               | ボディを修正して再送信                                                                                                      |
| 400   | `Invalid ID format`               | 指定された Short ID をデコードできませんでした  | `id` のフォーマットを修正して再送信                                                                                             |
| 400   | `No test version found`           | 商品にテスト環境のバージョンがまだ存在しない        | まず [Create Product](/api-reference/endpoints/onetime-products/create-product) で商品を作成                             |
| 400   | `Test version is not active`      | 現在のテストバージョンのステータスが `inactive` | 先に [Update Status](/api-reference/endpoints/onetime-products/update-status) でテストバージョンを有効化                        |
| 400   | `Already published to production` | 商品は既に本番バージョンを持っている            | 以降の変更は [Update Product](/api-reference/endpoints/onetime-products/update-product) に `X-Environment: prod` を付けて実施 |
| 404   | `Product not found`               | 商品が存在しないかアクセスできません            | `id` が現在のマーチャントに属することを確認                                                                                         |
| 500   | `Internal server error`           | サーバ側の予期しない障害                  | 指数バックオフでリトライ（5s 開始、最大 3 回）                                                                                       |
