跳转到内容
免费试用 14 天
简体中文
在 Claude 中打开 就此页面提问在 ChatGPT 中打开 就此页面提问

使用 API 更新/编辑 Wholesale Pricing

通过公共 API 更新现有的 Wholesale Pricing 规则,包含完整的请求正文参考。

本文介绍如何使用公共 API 更新现有的 Wholesale Pricing 规则。


要更新现有的 Wholesale Pricing 记录,请使用以下端点:

PUT https://wholesale.samita.io/api/v1/wholesale-pricings/{id}
  • {id} 是 Wholesale Pricing 记录的 ID
  • 可在应用界面中获取该 ID(不含“#”符号)
  • 参考示例:

PUT https://wholesale.samita.io/api/v1/wholesale-pricings/1

所有 API 请求都必须包含以下必填请求头:

请求头 说明 必填
X-SAMITA-API-KEY Wholesale 应用中提供的 API 密钥 是
X-SAMITA-SHOP-URL Shopify 商店域名,格式为 xxx.myshopify.com 是
CONTENT-TYPE 必须为 application/json 是

如果缺少任何必填请求头,请求将被拒绝。


_ 用于更新 Wholesale Pricing 的数据必须以 JSON 格式发送。本文末尾提供了示例 JSON 结构。

_ 请求中只需包含要更新的字段。与 Create API 方法不同,无需发送所有字段。

_ 未指定的字段将保持不变

示例请求 JSON:

{
"title": "New Wholesale Pricing",
"status": true,
"apply_customer": {
"type": "all",
"tags": []
},
"exclude_customer": {
"type": "none",
"tags": []
},
"apply_product": {
"type": "all",
"product_ids": [],
"product_tags": [],
"collection_ids": [],
"apply_for_variants": false
},
"exclude_product": {
"type": "none",
"product_ids": [],
"collection_ids": []
},
"discount_for_variants": [
{
"id": 8516448190631,
"variant_pricing": true,
"variants": [
{
"id": 46747346763943,
"discount_groups": [
{
"name": "all",
"type": "percent",
"value": "10"
}
]
}
]
}
],
"apply_market": {
"type": "all",
"handle": []
},
"discount_group": {
"type": "percent",
"value": "10"
},
"active_date": {
"types": ["start_date", "end_date"],
"start_at": "2026-01-15 10:00:00",
"end_at": "2026-01-15 10:00:00"
}
}

  • 用于标识 Wholesale Pricing 记录的名称
  • 在 Update API 中为可选
  • 必须为字符串
  • 最大长度:255 个字符

  • 定义记录是否启用
  • 在 Update API 中为可选
  • 仅接受以下值:
值 说明
true 定价规则已启用
false 定价规则未启用

定义哪些客户符合此定价规则。

结构:

"apply_customer": {
"type": "all",
"tags": []
}

type

可接受的值:

  • all
  • logged
  • non-logged
  • customer-tags

tags

  • 仅当 type == customer-tags 时必填
  • 必须为以逗号分隔的数组
  • 示例:["wholesale","b2b"]

用于将特定客户排除在定价规则之外。

结构:

"exclude_customer": {
"type": "none",
"tags": []
}

type

  • 默认值:none
  • 可接受的值:
值 说明
none 不排除任何客户
customer-tags 按标签排除客户

tags

  • 仅当 type == customer-tags 时必填
  • 示例:["vip","wholesale"]

定义定价规则适用于哪些产品。

结构:

"apply_product": {
"type": "all",
"product_ids": [],
"product_tags": [],
"collection_ids": [],
"apply_for_variants": false
}

type

可接受的值:

  • all
  • products
  • collections
  • product-tags

其他字段是否必填取决于所选的 type:

  • product_ids → 如果 type == products,则必填
  • product_tags → 如果 type == product-tags,则必填
  • collection_ids → 如果 type == collections,则必填

apply_for_variants

  • 可接受的值:true 或 false
  • 默认值:false

定义要排除在规则之外的产品。

结构:

"exclude_product": {
"type": "none",
"product_ids": [],
"collection_ids": []
}

可接受的类型:

  • none
  • products
  • collections

在按多属性配置折扣时使用。

  • 如果 apply_product.apply_for_variants == false,则必须为空
  • 当 apply_product.apply_for_variants == true 时必填

示例结构:

"discount_for_variants": [
  {
    "id": 8516448190631,
    "variant_pricing": true,
    "variants": [
      {
        "id": 46747346763943,
        "discount_groups": [
          {
            "name": "all",
            "type": "percent",
            "value": "10"
          }
        ]
      }
    ]
  }
]

结构:

  • 产品数组
  • 每个产品包含:
    • id – 产品 ID
    • variant_pricing – 必须为 true
    • variants – 多属性数组

每个多属性包含:

  • id – 多属性 ID
  • discount_groups – 折扣配置数组

discount_groups 规则

  • 如果 apply_customer.type 为 all、logged 或 non-logged
    → 只允许 一项
  • 如果 apply_customer.type == customer-tags
    → 可以提供多个折扣组

discount_groups 中的字段:

字段 说明
name 必须与客户类型或客户标签匹配
type 折扣类型
value 折扣值

可接受的折扣类型:

  • percent
  • amount
  • fixed-amount

值的规则:

  • 必须是大于 0 的数字
  • 如果 type 为 percent,value 必须小于 100

定义规则适用于哪些 Shopify 市场。

结构:

"apply_market": {
"type": "all",
"handle": []
}

type

可接受的值:

  • all
  • specific-market

handle

  • 仅当 type == specific-market 时必填
  • 以逗号分隔的市场 handle 列表
  • 示例:["japan","us"]

在未按多属性配置折扣时使用。

在以下情况下必填:

  • apply_product.type 不是 products,或
  • apply_product.type == products 且未应用多属性

结构:

"discount_group": {
"type": "percent",
"value": "10"
}

规则:

  • type 必须为以下之一:
    • percent
    • amount
    • fixed-amount
  • value
    • 必须大于 0
    • 如果 type 为 percent,value 必须小于 100

用于配置定价规则的开始和结束时间。

结构:

"active_date": {
"types": ["start_date", "end_date"],
"start_at": "2026-01-15T10:00:00",
"end_at": "2026-01-15T10:00:00"
}

types

  • 可选
  • 可接受的值:start_date、end_date
  • 示例:["start_date","end_date"]

start_at

  • 如果 types 包含 start_date,则为必填
  • 格式:YYYY-MM-DD HH:MM:SS

end_at

  • 如果 types 包含 end_date,则为必填
  • 格式:YYYY-MM-DD HH:MM:SS

401 – Unauthorized

可能的原因:

  • 缺少商店 URL
  • 缺少 API 密钥
  • 商店 URL 无效
  • API 密钥无效
  • API 密钥与商店不匹配

403 – This action is unauthorized

  • API 密钥没有 Update 权限
  • 每个 API 密钥可拥有:View、Create、Update、Delete 权限
  • 此 API 需要 Update 权限
  • 所提供的 ID 不存在时也会返回此错误

429 – Too Many Requests

超出速率限制:

  • 最多 每 5 分钟 1 次请求
  • 最多 每天 50 次请求

200 – API Success

  • Wholesale Pricing 记录更新成功
  • 响应以 JSON 格式返回

示例响应 JSON:

{
"id": 1,
"title": "New Wholesale Pricing",
"status": true,
"apply_customer": {
"type": "all",
"tags": []
},
"exclude_customer": {
"type": "none",
"tags": []
},
"apply_product": {
"type": "all",
"product_ids": [],
"product_tags": [],
"collection_ids": [],
"apply_for_variants": false
},
"exclude_product": {
"type": "none",
"product_ids": [],
"collection_ids": []
},
"discount_for_variants": [
{
"id": 8516448190631,
"variant_pricing": true,
"variants": [
{
"id": 46747346763943,
"discount_groups": [
{
"name": "all",
"type": "percent",
"value": "10"
}
]
}
]
}
],
"apply_market": {
"type": "all",
"handle": []
},
"discount_group": {
"type": "percent",
"value": "10"
},
"active_date": {
"types": [],
"start_at": "",
"end_at": ""
},
"created_at": "2026-01-15T10:00:00",
"updated_at": "2026-01-15T10:00:00"
}

这对您有帮助吗?