> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stateset.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Pricing Rule

> Create a dynamic pricing rule for products or customer segments

<Note>
  This endpoint creates a new pricing rule that automatically adjusts product prices based on various conditions like customer type, quantity, date ranges, or inventory levels.
</Note>

## Authentication

This endpoint requires a valid API key with `pricing:write` permissions.

```bash theme={null}
Authorization: Bearer YOUR_API_KEY
```

## Request Body

<ParamField body="name" type="string" required>
  Pricing rule name
</ParamField>

<ParamField body="type" type="string" required>
  Rule type: "customer\_specific", "volume\_based", "time\_based", "channel\_based", "dynamic"
</ParamField>

<ParamField body="priority" type="integer" required>
  Rule priority (lower numbers take precedence)
</ParamField>

<ParamField body="price_adjustment" type="object" required>
  Price adjustment configuration

  <Expandable title="Price adjustment properties">
    <ParamField body="method" type="string" required>
      Adjustment method: "fixed\_price", "percentage\_discount", "fixed\_discount", "markup", "formula"
    </ParamField>

    <ParamField body="value" type="number">
      Adjustment value (percentage for percentage methods, cents for fixed methods)
    </ParamField>

    <ParamField body="formula" type="string">
      Pricing formula (for formula method)
    </ParamField>

    <ParamField body="round_to" type="integer">
      Round final price to nearest value in cents
    </ParamField>

    <ParamField body="minimum_margin" type="number">
      Minimum margin percentage to maintain
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="conditions" type="object" required>
  Conditions for rule application

  <Expandable title="Condition properties">
    <ParamField body="customer_segments" type="array">
      Applicable customer segment IDs
    </ParamField>

    <ParamField body="customer_ids" type="array">
      Specific customer IDs
    </ParamField>

    <ParamField body="product_ids" type="array">
      Applicable product IDs
    </ParamField>

    <ParamField body="category_ids" type="array">
      Applicable category IDs
    </ParamField>

    <ParamField body="sku_patterns" type="array">
      SKU patterns (supports wildcards)
    </ParamField>

    <ParamField body="channels" type="array">
      Sales channels: "web", "pos", "b2b", "marketplace"
    </ParamField>

    <ParamField body="quantity_breaks" type="array">
      Volume-based pricing tiers

      <Expandable title="Quantity break properties">
        <ParamField body="min_quantity" type="integer" required>
          Minimum quantity for this tier
        </ParamField>

        <ParamField body="adjustment" type="object" required>
          Price adjustment for this tier
        </ParamField>
      </Expandable>
    </ParamField>

    <ParamField body="inventory_threshold" type="object">
      Dynamic pricing based on inventory

      <Expandable title="Inventory threshold properties">
        <ParamField body="low_stock" type="integer">
          Low stock threshold
        </ParamField>

        <ParamField body="high_stock" type="integer">
          High stock threshold
        </ParamField>

        <ParamField body="adjustment_curve" type="string">
          Price adjustment curve: "linear", "exponential", "stepped"
        </ParamField>
      </Expandable>
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="validity" type="object" required>
  Rule validity period

  <Expandable title="Validity properties">
    <ParamField body="start_date" type="string" required>
      Start date (ISO 8601)
    </ParamField>

    <ParamField body="end_date" type="string">
      End date (ISO 8601)
    </ParamField>

    <ParamField body="schedule" type="object">
      Time-based schedule

      <Expandable title="Schedule properties">
        <ParamField body="days_of_week" type="array">
          Active days (0-6, Sunday is 0)
        </ParamField>

        <ParamField body="time_ranges" type="array">
          Active time ranges
        </ParamField>
      </Expandable>
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="currency" type="string">
  Currency code (defaults to account currency)
</ParamField>

<ParamField body="status" type="string">
  Rule status: "active", "scheduled", "inactive"
</ParamField>

<ParamField body="metadata" type="object">
  Additional custom fields
</ParamField>

### Response

Returns the created pricing rule object.

<RequestExample>
  ```bash cURL theme={null}
  curl --location --request POST 'https://api.stateset.com/v1/pricing-rules' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --data-raw '{
      "name": "B2B Volume Pricing - Electronics",
      "type": "volume_based",
      "priority": 10,
      "price_adjustment": {
          "method": "percentage_discount",
          "round_to": 99,
          "minimum_margin": 15
      },
      "conditions": {
          "customer_segments": ["wholesale", "distributor"],
          "category_ids": ["cat_electronics"],
          "quantity_breaks": [
              {
                  "min_quantity": 10,
                  "adjustment": {
                      "method": "percentage_discount",
                      "value": 10
                  }
              },
              {
                  "min_quantity": 50,
                  "adjustment": {
                      "method": "percentage_discount",
                      "value": 15
                  }
              },
              {
                  "min_quantity": 100,
                  "adjustment": {
                      "method": "percentage_discount",
                      "value": 20
                  }
              }
          ]
      },
      "validity": {
          "start_date": "2024-01-01T00:00:00Z"
      },
      "status": "active"
  }'
  ```

  ```javascript Node.js theme={null}
  const pricingRule = await stateset.pricingRules.create({
    name: "B2B Volume Pricing - Electronics",
    type: "volume_based",
    priority: 10,
    price_adjustment: {
      method: "percentage_discount",
      round_to: 99,
      minimum_margin: 15
    },
    conditions: {
      customer_segments: ["wholesale", "distributor"],
      category_ids: ["cat_electronics"],
      quantity_breaks: [
        {
          min_quantity: 10,
          adjustment: {
            method: "percentage_discount",
            value: 10
          }
        },
        {
          min_quantity: 50,
          adjustment: {
            method: "percentage_discount",
            value: 15
          }
        },
        {
          min_quantity: 100,
          adjustment: {
            method: "percentage_discount",
            value: 20
          }
        }
      ]
    },
    validity: {
      start_date: "2024-01-01T00:00:00Z"
    },
    status: "active"
  });
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "id": "pr_0901f083-aa1c-43c5-af5c-0a9d2fc64e30",
    "object": "pricing_rule",
    "name": "B2B Volume Pricing - Electronics",
    "type": "volume_based",
    "priority": 10,
    "price_adjustment": {
      "method": "percentage_discount",
      "round_to": 99,
      "minimum_margin": 15
    },
    "conditions": {
      "customer_segments": ["wholesale", "distributor"],
      "customer_ids": [],
      "product_ids": [],
      "category_ids": ["cat_electronics"],
      "sku_patterns": [],
      "channels": [],
      "quantity_breaks": [
        {
          "min_quantity": 10,
          "max_quantity": 49,
          "adjustment": {
            "method": "percentage_discount",
            "value": 10
          }
        },
        {
          "min_quantity": 50,
          "max_quantity": 99,
          "adjustment": {
            "method": "percentage_discount",
            "value": 15
          }
        },
        {
          "min_quantity": 100,
          "max_quantity": null,
          "adjustment": {
            "method": "percentage_discount",
            "value": 20
          }
        }
      ]
    },
    "validity": {
      "start_date": "2024-01-01T00:00:00Z",
      "end_date": null,
      "is_active": true,
      "schedule": null
    },
    "currency": "USD",
    "status": "active",
    "created_at": "2024-01-20T13:00:00Z",
    "updated_at": "2024-01-20T13:00:00Z",
    "created_by": "user_123",
    "statistics": {
      "times_applied": 0,
      "total_discount_given": 0,
      "affected_orders": 0,
      "last_applied": null
    }
  }
  ```
</ResponseExample>
