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

# 创建门店

> 为已认证的商户创建新门店

为已认证的商户创建新门店。门店 slug 由名称自动生成，JSONB 配置字段（`notificationSettings`、`checkoutSettings`）以默认值初始化。Webhook 通过 [`add-webhook`](/zh/api-reference/endpoints/webhooks/add-webhook) 单独管理 -- 新创建的门店不存在任何 webhook 记录。

```
POST /v1/actions/store/create-store
```

**认证方式：** API Key

## 请求体

| 字段     | 类型     | 必需 | 说明                     |
| ------ | ------ | -- | ---------------------- |
| `name` | string | 是  | 门店名称（1-48 字符，自动去除首尾空格） |

## 请求示例

<CodeGroup>
  ```typescript SDK theme={"system"}
  import { WaffoPancake } from "@waffo/pancake-ts";

  const client = new WaffoPancake({
    merchantId: process.env.WAFFO_MERCHANT_ID!,
    privateKey: process.env.WAFFO_PRIVATE_KEY!,
  });

  const { store } = await client.stores.create({ name: "My Digital Store" });
  console.log(store.id);   // => "STO_2aUyqjCzEIiEcYMKj7TZtw"
  console.log(store.slug); // => "my-digital-store-a1b2c3"
  ```

  ```typescript TypeScript (fetch) theme={"system"}
  // Uses callApi() helper from authentication.mdx
  const result = await callApi("POST", "/v1/actions/store/create-store", {
    name: "My Digital Store",
  });
  console.log(result.data.store.id);   // => "STO_2aUyqjCzEIiEcYMKj7TZtw"
  console.log(result.data.store.slug); // => "my-digital-store-a1b2c3"
  ```

  ```java Java theme={"system"}
  // Uses callApi() helper from authentication.mdx
  String body = """
      {"name":"My Digital Store"}""";

  String response = callApi("POST", "/v1/actions/store/create-store", body);
  System.out.println(response);
  // => {"data":{"store":{"id":"STO_2aUyqjCzEIiEcYMKj7TZtw","slug":"my-digital-store-a1b2c3",...}}}
  ```

  ```python Python theme={"system"}
  # Uses call_api() helper from authentication.mdx
  result = call_api("POST", "/v1/actions/store/create-store", {
      "name": "My Digital Store",
  })
  store = result["data"]["store"]
  print(store["id"])    # => "STO_2aUyqjCzEIiEcYMKj7TZtw"
  print(store["slug"])  # => "my-digital-store-a1b2c3"
  ```

  ```go Go theme={"system"}
  // Uses callAPI() helper from authentication.mdx
  body := map[string]interface{}{
      "name": "My Digital Store",
  }
  result, err := callAPI("POST", "/v1/actions/store/create-store", body)
  if err != nil {
      log.Fatal(err)
  }
  fmt.Println(string(result))
  // => {"data":{"store":{"id":"STO_2aUyqjCzEIiEcYMKj7TZtw","slug":"my-digital-store-a1b2c3",...}}}
  ```

  ```rust Rust theme={"system"}
  // Uses call_api() helper from authentication.mdx
  let body = serde_json::json!({
      "name": "My Digital Store"
  });
  let result = call_api("POST", "/v1/actions/store/create-store", &body).await?;
  println!("{}", result);
  // => {"data":{"store":{"id":"STO_2aUyqjCzEIiEcYMKj7TZtw","slug":"my-digital-store-a1b2c3",...}}}
  ```

  ```c C theme={"system"}
  /* Uses call_api() helper from authentication.mdx */
  const char *body = "{\"name\":\"My Digital Store\"}";
  char *response = call_api("POST", "/v1/actions/store/create-store", body);
  printf("%s\n", response);
  free(response);
  ```

  ```cpp C++ theme={"system"}
  // Uses callApi() helper from authentication.mdx
  std::string body = R"({"name":"My Digital Store"})";
  std::string response = callApi("POST", "/v1/actions/store/create-store", body);
  std::cout << response << std::endl;
  // => {"data":{"store":{"id":"STO_2aUyqjCzEIiEcYMKj7TZtw","slug":"my-digital-store-a1b2c3",...}}}
  ```

  ```bash cURL theme={"system"}
  MERCHANT_ID="MER_2aUyqjCzEIiEcYMKj7TZtw"
  TIMESTAMP=$(date +%s)
  BODY='{"name":"My Digital Store"}'
  BODY_HASH=$(echo -n "$BODY" | openssl dgst -sha256 -binary | base64 -w 0)
  CANONICAL_REQUEST="POST
  /v1/actions/store/create-store
  $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/store/create-store" \
    -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='{"name":"My Digital Store"}'
  BODY_HASH=$(echo -n "$BODY" | openssl dgst -sha256 -binary | base64 -w 0)
  CANONICAL_REQUEST="POST
  /v1/actions/store/create-store
  $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/store/create-store" \
    --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": {
    "store": {
      "id": "STO_2aUyqjCzEIiEcYMKj7TZtw",
      "name": "My Digital Store",
      "status": "active",
      "logo": null,
      "supportEmail": null,
      "website": null,
      "slug": "my-digital-store-a1b2c3",
      "prodEnabled": false,
      "notificationSettings": {
        "emailOrderConfirmation": true,
        "emailSubscriptionConfirmation": true,
        "emailSubscriptionCycled": true,
        "emailSubscriptionCanceled": true,
        "emailSubscriptionRevoked": true,
        "emailSubscriptionPastDue": true,
        "notifyNewOrders": true,
        "notifyNewSubscriptions": true
      },
      "checkoutSettings": {
        "defaultDarkMode": false,
        "light": {
          "checkoutLogo": null,
          "checkoutColorPrimary": "#000000",
          "checkoutColorBackground": "#FFFFFF",
          "checkoutColorCard": "#F5F5F5",
          "checkoutColorText": "#1A1A1A",
          "checkoutBorderRadius": "8px"
        },
        "dark": {
          "checkoutLogo": null,
          "checkoutColorPrimary": "#FFFFFF",
          "checkoutColorBackground": "#1A1A1A",
          "checkoutColorCard": "#2A2A2A",
          "checkoutColorText": "#F5F5F5",
          "checkoutBorderRadius": "8px"
        }
      },
      "deletedAt": null,
      "createdAt": "2026-01-15T10:30:00.000Z",
      "updatedAt": "2026-01-15T10:30:00.000Z"
    }
  }
}
```

## 响应字段

| 字段                     | 类型             | 说明                                                                                       |
| ---------------------- | -------------- | ---------------------------------------------------------------------------------------- |
| `id`                   | string         | Store ID（Short ID 格式 `STO_xxx`）                                                          |
| `name`                 | string         | 门店显示名称                                                                                   |
| `status`               | string         | 门店状态（`active`、`inactive` 或 `suspended`）                                                  |
| `logo`                 | string \| null | 门店 logo URL                                                                              |
| `supportEmail`         | string \| null | 客服邮箱                                                                                     |
| `website`              | string \| null | 门店网站 URL                                                                                 |
| `slug`                 | string \| null | 自动生成的 URL slug                                                                           |
| `prodEnabled`          | boolean        | 是否已启用生产模式                                                                                |
| `notificationSettings` | object \| null | 通知偏好设置（参见 [通知设置](/zh/api-reference/endpoints/stores/update-store#notification-settings)） |
| `checkoutSettings`     | object \| null | 收银台页面主题（参见 [收银台设置](/zh/api-reference/endpoints/stores/update-store#checkout-settings)）   |
| `deletedAt`            | string \| null | 软删除时间戳（ISO 8601），活跃时为 `null`                                                             |
| `createdAt`            | string         | 创建时间戳（ISO 8601）                                                                          |
| `updatedAt`            | string         | 最后更新时间戳（ISO 8601）                                                                        |

## 错误响应

> **重试策略**：4xx 一律不要重试 — 修正请求后重发。5xx 指数退避重试（起步 5s，最多 3 次）。

| 状态码 | `errors[0].message`                                                                    | 含义                   | 推荐处理                          |
| --- | -------------------------------------------------------------------------------------- | -------------------- | ----------------------------- |
| 400 | `Missing merchantId in request context`                                                | API Key 未解析出商户上下文    | **不要重试**。检查 API Key 配置。       |
| 400 | `Missing required field: name`                                                         | 请求体未传 `name`         | 修正输入后重新提交。                    |
| 400 | `Store name cannot be empty or contain only whitespace`                                | `trim()` 后 `name` 为空 | 修正输入后重新提交。                    |
| 400 | `Store name cannot exceed 48 characters`                                               | `name` 超过 48 字符      | 缩短名称后重新提交。                    |
| 400 | `Cannot create more stores. Maximum limit of 20 stores per merchant has been reached.` | 商户已拥有 20 个门店         | **不要重试**。先删除一个现有门店，或联系支持提升上限。 |

<Note>
  每个商户最多可创建 **20 个门店**。门店创建者自动被分配 `owner` 角色。
</Note>
