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

# Calculate Price

> Calculate prices with applicable pricing rules

<Note>
  This endpoint calculates final prices for products by applying all applicable pricing rules based on customer, quantity, and other conditions.
</Note>

## Authentication

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

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

## Request Body

<ParamField body="customer_id" type="string">
  Customer ID for customer-specific pricing
</ParamField>

<ParamField body="customer_segment" type="string">
  Customer segment if customer\_id not provided
</ParamField>

<ParamField body="channel" type="string">
  Sales channel: "web", "pos", "b2b", "marketplace"
</ParamField>

<ParamField body="items" type="array" required>
  Products to calculate pricing for

  <Expandable title="Item properties">
    <ParamField body="product_id" type="string" required>
      Product ID
    </ParamField>

    <ParamField body="variant_id" type="string">
      Product variant ID
    </ParamField>

    <ParamField body="quantity" type="integer" required>
      Quantity
    </ParamField>

    <ParamField body="list_price" type="integer" required>
      Original list price in cents
    </ParamField>

    <ParamField body="category_id" type="string">
      Product category ID
    </ParamField>

    <ParamField body="sku" type="string">
      Product SKU
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="currency" type="string">
  Currency code (default: account currency)
</ParamField>

<ParamField body="date" type="string">
  Date for time-based pricing (ISO 8601)
</ParamField>

### Response

Returns calculated prices with applied rules breakdown.

<RequestExample>
  ```bash cURL theme={null}
  curl --location --request POST 'https://api.stateset.com/v1/pricing-rules/calculate' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --data-raw '{
      "customer_segment": "wholesale",
      "channel": "b2b",
      "items": [
          {
              "product_id": "prod_electronics_001",
              "quantity": 75,
              "list_price": 9999,
              "category_id": "cat_electronics"
          },
          {
              "product_id": "prod_accessories_001",
              "quantity": 10,
              "list_price": 1999,
              "category_id": "cat_accessories"
          }
      ]
  }'
  ```

  ```javascript Node.js theme={null}
  const calculation = await stateset.pricingRules.calculate({
    customer_segment: "wholesale",
    channel: "b2b",
    items: [
      {
        product_id: "prod_electronics_001",
        quantity: 75,
        list_price: 9999,
        category_id: "cat_electronics"
      },
      {
        product_id: "prod_accessories_001",
        quantity: 10,
        list_price: 1999,
        category_id: "cat_accessories"
      }
    ]
  });
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "object": "price_calculation",
    "items": [
      {
        "product_id": "prod_electronics_001",
        "quantity": 75,
        "list_price": 9999,
        "final_price": 8499,
        "unit_discount": 1500,
        "total_discount": 112500,
        "subtotal": 637425,
        "applied_rules": [
          {
            "rule_id": "pr_0901f083-aa1c-43c5-af5c-0a9d2fc64e30",
            "rule_name": "B2B Volume Pricing - Electronics",
            "type": "volume_based",
            "discount_percentage": 15,
            "quantity_tier": "50-99"
          }
        ]
      },
      {
        "product_id": "prod_accessories_001",
        "quantity": 10,
        "list_price": 1999,
        "final_price": 1999,
        "unit_discount": 0,
        "total_discount": 0,
        "subtotal": 19990,
        "applied_rules": [],
        "reason_no_discount": "category_not_eligible"
      }
    ],
    "summary": {
      "total_list_price": 769915,
      "total_discount": 112500,
      "total_final_price": 657415,
      "discount_percentage": 14.6,
      "currency": "USD"
    },
    "rules_considered": 3,
    "rules_applied": 1,
    "calculation_timestamp": "2024-06-20T16:30:00Z"
  }
  ```
</ResponseExample>
