**版本：202201**

# 更新价格规则

**PUT** `/openapi/2022-01/price_rules/:price_rule_id`

通过指定价格规则 ID 和新参数修改现有价格规则。

## 请求

**Path参数**

- `price_rule_id` string (required)

  价格规则 ID。

**application/json**

**请求体 | 示例**

**请求体**

- `price_rule` object

  - `title` string

    Title of this price rule
  - `value` double

    Value for this discount , e.g. `50.25`
  - `value_type` string

    Discount type, options: 1. `fixed_amount` for fixed amount of value to be reduced, 2. `percentage` for percentage of the value to be reduced
  - `usage_limit` int32

    The usage limit, `-1` means no limit
  - `allocation_limit` int32

    Redeem count limit for checkout: `0~999`, `0` means only one redeem allowed, `999` means no limit
  - `once_per_customer` int32

    The max usage per customer，`-1` or `0` means no limit
  - `prerequisite` int32

    Does this discount has prerequisite or not, `1` means yes, `0` means no

    **默认值：** `1`
  - `target_selection` string

    The target products allowed of this discount, `all` means all products, `entitled` means only for the specific products
  - `target_type` string

    Target type of this discount, for example: `line_item`, `shipping_line`
  - `starts_at` string

    Discount started at
  - `ends_at` string

    Discount ended at, `-1` means no limit
  - `entitled_product_ids` string[]

    Specify the target products allowed for the price rule. This field is **required** only when `target_selection` is `entitled`, e.g. `[ "ac8ed089-55d9-4f58-a0f9-3dda4e4607cc", "0b76afba-e068-4bf6-85f5-660019f58488" ]`
  - `entitled_variant_ids` string[]

    Specify the variants products allowed of the discount, e.g. `[ "cea210d5-a419-4d4e-a17d-5bbd0bc4af76", "de2c55f5-c3e1-45e1-92f6-e65faf816ecc" ]`
  - `entitled_collection_ids` string[]

    Specify the collections allowed of the discount, e.g. `["aa92c677-e5be-4cab-8e65-9ebc55b98240","e6152ca6-791b-4385-a9e1-49adb336b289"]`
  - `prerequisite_subtotal_range` object[]

    Prerequisite for the total amount of the money, for example: `[ { "greater_than_or_equal_to": "10", "value": "1", "target_type": "", "target_data": [] } ] means total money must great than 10, then you could use the discount to reduce 1 dollar.`

    *   Array [

    - `greater_than_or_equal_to` string

      To specify the value which the price has to greater than or equal to.
    - `value` string

      The value used for the discount to apply, the reduction type is decided by `value_type` specified in `Price Rule` params
    - `target_type` string

      Target type
    - `target_data` string[]

      Target data

      **默认值：** `[]`
    *   ]
  - `prerequisite_quantity_range` object[]

    Prerequisite for the total count of the products，e.g. `[ { "greater_than_or_equal_to":"5", "value":"20", "target_type":"", "target_data":[] } ] means products count must great than 5, then you could use discount to reduce 20 dollars`

    *   Array [

    - `greater_than_or_equal_to` string

      To specify the value which the price has to greater than or equal to.
    - `value` string

      The value used for the discount to apply, the reduction type is decided by `value_type` specified in `Price Rule` params
    - `target_type` string

      Target type
    - `target_data` string[]

      Target data

      **默认值：** `[]`
    *   ]

```json
{
  "price_rule": {
    "title": "string",
    "value": 0,
    "value_type": "string",
    "usage_limit": 0,
    "allocation_limit": 0,
    "once_per_customer": 0,
    "prerequisite": 1,
    "target_selection": "string",
    "target_type": "string",
    "starts_at": "string",
    "ends_at": "string",
    "entitled_product_ids": [
      "string"
    ],
    "entitled_variant_ids": [
      "string"
    ],
    "entitled_collection_ids": [
      "string"
    ],
    "prerequisite_subtotal_range": [
      {
        "greater_than_or_equal_to": "string",
        "value": "string",
        "target_type": "string",
        "target_data": [
          "string"
        ]
      }
    ],
    "prerequisite_quantity_range": [
      {
        "greater_than_or_equal_to": "string",
        "value": "string",
        "target_type": "string",
        "target_data": [
          "string"
        ]
      }
    ]
  }
}
```

## 响应

**200 | 404**

200

**application/json**

**数据结构 | 示例 | Result**

**数据结构**

- `price_rule` object

  - `id` string

    **示例：** `00095d6a-419d-4499-a497-f265fb2edaa5`
  - `title` string

    **示例：** `title-update`
  - `value` integer

    **默认值：** `0`

    **示例：** `0`
  - `value_type` string

    **示例：** `percentage`
  - `usage_limit` string

    **示例：** `-1`
  - `times_used` string

    **示例：** `0`
  - `allocation_method` string

    **示例：**
  - `allocation_limit` string

    **示例：** `0`
  - `once_per_customer` string

    **示例：** `1`
  - `prerequisite` string

    **示例：** `1`
  - `customer_selection` string

    **示例：** `all`
  - `target_selection` string

    **示例：** `entitled`
  - `target_type` string

    **示例：**
  - `created_at` string

    **示例：** `2020-03-06 17:00:32`
  - `updated_at` string

    **示例：** `2020-03-12 15:29:44`
  - `starts_at` string

    **示例：** `1583424000`
  - `ends_at` string

    **示例：** `1583942399`
  - `entitled_product_ids` string[]
  - `entitled_variant_ids` array
  - `prerequisite_quantity_range` object[]

    *   Array [

    - `greater_than_or_equal_to` string

      **示例：** `1`
    - `value` string

      **示例：** `5`
    - `target_type` string

      **示例：**
    - `target_data` array
    *   ]
  - `prerequisite_subtotal_range`

```json
{
  "price_rule": {
    "id": "00095d6a-419d-4499-a497-f265fb2edaa5",
    "title": "title-update",
    "value": 0,
    "value_type": "percentage",
    "usage_limit": "-1",
    "times_used": "0",
    "allocation_method": "",
    "allocation_limit": "0",
    "once_per_customer": "1",
    "prerequisite": "1",
    "customer_selection": "all",
    "target_selection": "entitled",
    "target_type": "",
    "created_at": "2020-03-06 17:00:32",
    "updated_at": "2020-03-12 15:29:44",
    "starts_at": "1583424000",
    "ends_at": "1583942399",
    "entitled_product_ids": [
      "cea210d5-a419-4d4e-a17d-5bbd0bc4af76"
    ],
    "entitled_variant_ids": [
      null
    ],
    "prerequisite_quantity_range": [
      {
        "greater_than_or_equal_to": "1",
        "value": "5",
        "target_type": "",
        "target_data": [
          null
        ]
      }
    ],
    "prerequisite_subtotal_range": {}
  }
}
```

```json
{
    "price_rule": {
        "id": "00095d6a-419d-4499-a497-f265fb2edaa5",
        "title": "title-update",
        "value": 0,
        "value_type": "percentage",
        "usage_limit": "-1",
        "times_used": "0",
        "allocation_method": "",
        "allocation_limit": "0",
        "once_per_customer": "1",
        "prerequisite": "1",
        "customer_selection": "all",
        "target_selection": "entitled",
        "target_type": "",
        "created_at": "2020-03-06 17:00:32",
        "updated_at": "2020-03-12 15:29:44",
        "starts_at": "1583424000",
        "ends_at": "1583942399",
        "entitled_product_ids": [
            "cea210d5-a419-4d4e-a17d-5bbd0bc4af76",
            "de2c55f5-c3e1-45e1-92f6-e65faf816ecc",
            "47734e19-1b5c-468b-8695-31159d6d4478"
        ],
        "entitled_variant_ids": [],
        "prerequisite_quantity_range": [
            {
                "greater_than_or_equal_to": "1",
                "value": "5",
                "target_type": "",
                "target_data": []
            }
        ],
        "prerequisite_subtotal_range": null
    }
}
```

404

**application/json**

**数据结构 | 示例 | Result**

**数据结构**

- `errors` string[]

```json
{
  "errors": [
    "Not found"
  ]
}
```

```json
{
    "errors": [
        "Not found"
    ]
}
```
