> For the complete documentation index, see [llms.txt](https://docs-shpf.bsscommerce.com/b2b-wholesale-solution/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-shpf.bsscommerce.com/b2b-wholesale-solution/api-integration/public-apis/public-apis-for-custom-pricing-cp.md).

# 🔗Public APIs for Custom Pricing (CP)

The **Custom Pricing Public API** is a feature of the **BSS B2B Solution** Shopify app.\
It allows developers to manage and sync **customer-specific pricing rules** directly from external systems such as ERPs, CRMs, or custom integrations.

These are **REST APIs** — you can use them to:

* Manage customer pricing rules
* Calculate variant prices based on active rules
* Retrieve product and customer data
* Automate B2B price synchronization

***

## 🔑 Get the Access Key

1. Get your API Key. If you don’t have one yet, please [follow this document](/b2b-wholesale-solution/api-integration/public-apis.md) to generate it.
2. Include it in the request body for endpoints that require it.

***

## 🧱 Rule Endpoints

Before using the endpoints, familiarize yourself with the **Rule model fields** below.

| Field                    | Description                                         | Values                                                                                                                                                                                        |
| ------------------------ | --------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `priority`               | Determines which rule takes precedence over others. | Integer                                                                                                                                                                                       |
| `status`                 | Activation status of the rule.                      | <p><code>0</code>: Inactive<br><code>1</code>: Active</p>                                                                                                                                     |
| `apply_to`               | Defines which customers the rule applies to.        | <p><code>0</code>: All customers<br><code>1</code>: Logged-in customers<br><code>2</code>: Not-logged-in customers<br><code>3</code>: Specific customers<br><code>4</code>: Customer tags</p> |
| `exclude_customer`       | Exclude rules for certain customers.                | <p><code>0</code>: None<br><code>1</code>: Customer tags<br><code>2</code>: Specific customers</p>                                                                                            |
| `product_condition_type` | Determines which products are targeted.             | <p><code>0</code>: All products<br><code>1</code>: Specific products<br><code>2</code>: Product collections<br><code>3</code>: Product tags<br><code>4</code>: Specific variants</p>          |
| `exc_product_type`       | Excludes certain products from the rule.            | <p><code>0</code>: None<br><code>1</code>: Specific products<br><code>2</code>: Product collections<br><code>3</code>: Product tags<br><code>4</code>: Specific variants</p>                  |
| `discount_type`          | Discount method to apply.                           | <p><code>0</code>: Apply a fixed price<br><code>1</code>: Subtract a fixed amount<br><code>2</code>: Subtract a percentage (%)</p>                                                            |
| `market_condition_type`  | Determines which markets the rule applies to.       | <p><code>0</code>: All markets<br><code>1</code>: Specific markets</p>                                                                                                                        |

***

### 📘 Get Rules by Domain

**Endpoint**

```
POST https://b2b-solution-public-api.bsscommerce.com/api/v1/rule/get-by-domain
```

**Headers**

```
Content-Type: application/json
```

**Request Body**

```json
{
  "domain": "abc.myshopify.com",
  "accessKey": "xxx"
}
```

**Response**

{% code expandable="true" %}

```json
{
  "success": true,
  "rules": [
    {
      "id": 536662,
      "shop_id": 9204,
      "name": "Discount 20%l",
      "priority": 1,
      "status": 1,
      "apply_to": 0,
      "customer_ids": [],
      "customer_tags": [],
      "product_condition_type": 4,
      "variant_ids": ["6586590625965", "6586590658733", "6586590691501"],
      "discount_type": 2,
      "discount_value": "10.00",
      "market_condition_type": 1,
      "market_ids": ["49314136349"],
      "createdAt": "2023-03-09T03:38:50.000Z",
      "updatedAt": "2023-06-15T02:16:47.000Z"
    },
    {
      "id": 545507,
      "name": "test4",
      "status": 0,
      "apply_to": 3,
      "customer_ids": ["6819529654557", "6905095291165"],
      "product_ids": ["8174450049309"],
      "discount_type": 0,
      "discount_value": "50.00",
      "market_condition_type": 0
    }
  ]
}
```

{% endcode %}

***

### 📗 Get Rule by ID

**Endpoint**

```
POST https://b2b-solution-public-api.bsscommerce.com/api/v1/rule/get-by-id
```

**Request Body**

```json
{
  "domain": "abc.myshopify.com",
  "accessKey": "xxx",
  "id": 79
}
```

**Response**

{% code expandable="true" %}

```json
{
  "success": true,
  "rule": {
    "id": 79,
    "name": "Discount 20%l",
    "priority": 1,
    "status": 1,
    "apply_to": 0,
    "variant_ids": ["6586590625965", "6586590658733", "6586590691501"],
    "discount_type": 2,
    "discount_value": "10.00",
    "market_condition_type": 1,
    "market_ids": ["49314136349"]
  }
}
```

{% endcode %}

***

### 📕 Get Rules by Products

**Endpoint**

```
POST https://b2b-solution-public-api.bsscommerce.com/api/v1/rule/get-rules-by-products
```

**Request Body**

```json
{
  "domain": "abc.myshopify.com",
  "accessKey": "xxx",
  "product_ids": [7208233467979, 7208233467980],
  "product_tags": ["b2b", "pants"]
}
```

> You can get rules either by **product IDs** or **product tags**.

**Response**

```json
{
  "success": true,
  "data": [
    { "productId": "8249126813999", "ruleId": 40, "ruleName": "VIP group", "appliedPrice": 27100 },
    { "productId": "8249222791471", "ruleId": 40, "ruleName": "VIP group", "appliedPrice": 63.5 }
  ]
}
```

***

### 📙 Get Rules by Customers

**Endpoint**

```
POST https://b2b-solution-public-api.bsscommerce.com/api/v1/rule/get-rules-by-customers
```

**Request Body**

```json
{
  "domain": "abc.myshopify.com",
  "accessKey": "xxx",
  "customer_ids": [7208233467979, 7208233467980],
  "customer_tags": ["b2b", "pants"]
}
```

> You can get rules by **customer IDs** or **customer tags**.

**Response**

{% code expandable="true" %}

```json
{
  "success": true,
  "data": [
    {
      "customerId": "6764123291723",
      "rules": [
        { "ruleId": 2151079182, "ruleName": "Wholesale", "customerTags": ["b2b"] }
      ]
    }
  ]
}
```

{% endcode %}

***

### ✏️ Create or Update a Single Rule

**Endpoint**

```
POST https://b2b-solution-public-api.bsscommerce.com/api/v1/rule/save
```

> If no `id` is provided, a new rule is created.\
> If `id` exists, the existing rule is updated.

**Request Body**

{% code expandable="true" %}

```json
{
  "domain": "abc.myshopify.com",
  "accessKey": "xxx",
  "rule": {
    "name": "Test rule",
    "priority": 1,
    "status": 0,
    "apply_to": 1,
    "product_condition_type": 4,
    "product_ids": ["5460196589730"],
    "discount_type": 2,
    "discount_value": "40",
    "exc_product_variants": [44531061752093, 45056544342301]
  }
}
```

{% endcode %}

**Response**

```json
{
  "success": true,
  "message": "Create the rule successfully",
  "ruleId": 11
}
```

***

### ✨ Create or Update Multiple Rules

**Endpoint**

```
POST https://b2b-solution-public-api.bsscommerce.com/api/v1/rule/bulk-save
```

**Request Body**

{% code expandable="true" %}

```json
{
  "domain": "abc.myshopify.com",
  "accessKey": "xxx",
  "rules": [
    {
      "name": "sencond1",
      "priority": 0,
      "status": 1,
      "discount_type": 2,
      "discount_value": 10.0
    },
    {
      "id": 545507,
      "name": "test4",
      "status": 0,
      "discount_type": 0,
      "discount_value": "50.00",
      "exc_product_tags": ["b2b", "wholesale"]
    }
  ]
}
```

{% endcode %}

**Response**

```json
{
  "success": true,
  "message": [
    "Create new rule 'sencond1' with ID 214780831 successfully",
    "Update rule 'test4' with ID 545507 successfully"
  ]
}
```

***

### ❌ Delete a Rule

```
POST https://b2b-solution-public-api.bsscommerce.com/api/v1/rule/delete
```

**Body**

```json
{
  "domain": "abc.myshopify.com",
  "accessKey": "xxx",
  "id": 79
}
```

**Response**

```json
{
  "success": true,
  "message": "Deleted rule ID 79 successfully"
}
```

***

### 🗑️ Delete Multiple Rules

```
POST https://b2b-solution-public-api.bsscommerce.com/api/v1/rule/mass-delete
```

**Body**

```json
{
  "domain": "abc.myshopify.com",
  "accessKey": "xxx",
  "ids": [79, 80, 81]
}
```

**Response**

```json
{
  "success": true,
  "message": "Deleted multiple rule successfully"
}
```

***

### 🧹 Remove Existing Products from Rules

```
PUT https://b2b-solution-public-api.bsscommerce.com/api/v1/rule/delete-items
```

**Request Body**

```json
{
  "domain": "abc.myshopify.com",
  "accessKey": "xxx",
  "rules": [
    {
      "id": 2,
      "product_condition_type": 1,
      "product_ids": ["8746948329722", "8746948821242"]
    }
  ]
}
```

**Response (Success)**

```json
{
  "success": true,
  "message": "Success",
  "data": {
    "success": ["Update rule with id 2 success"],
    "failed": []
  }
}
```

**Response (Error)**

```json
{
  "message": "Fail",
  "data": {
    "failed": [
      { "rule_id": 3, "errors": ["Invalid product_condition_type", "product_ids must be array"] }
    ]
  }
}
```

***

### 🧾 Get Applied Rules for Products

```
POST https://b2b-solution-public-api.bsscommerce.com/api/v1/rule/get-products-applied-rules
```

> If `customer_id` is `null`, the system checks rules that apply to **all** or **not-logged-in** customers.

**Request Body**

```json
{
  "domain": "abc.myshopify.com",
  "product_ids": [6586590625965, 6586590658733],
  "customer_id": 5127974846637,
  "accessKey": "xxxx"
}
```

**Response**

```json
{
  "success": true,
  "productsAppliedRule": [
    { "id": "6586590625965", "discount_type": 2, "value": "10.00", "name": "Discount 30%" }
  ]
}
```

***

### 💰 Get Variant Price List Based on Rules

```
POST https://b2b-solution-public-api.bsscommerce.com/api/v1/rule/get-variants-price-list
```

**Request Body**

```json
{
  "domain": "abc.myshopify.com",
  "product_ids": [6586590625965, 6586590658733],
  "customer_id": 5127974846637,
  "accessKey": "xxx"
}
```

**Response**

{% code expandable="true" %}

```json
{
  "success": true,
  "priceList": [
    {
      "id": "6586590625965",
      "discount_type": 2,
      "value": "10.00",
      "name": "Discount 30%",
      "variants": [
        {
          "id": "39454422368429",
          "price": "70",
          "compareAtPrice": "85",
          "appliedRulePrice": 63
        }
      ]
    }
  ]
}
```

{% endcode %}

***

## 🧭 Product Endpoints

All product endpoints follow the same pattern — `domain` + `accessKey` required.

### 🔎 Search Products

```
POST https://b2b-solution-public-api.bsscommerce.com/api/v1/product/search
```

**Cursor**\
`afterIndex` indicates where to continue fetching.\
If `null`, search starts from the beginning.

```json
{
  "domain": "abc.myshopify.com",
  "accessKey": "xxx",
  "afterIndex": null,
  "first": 20,
  "searchQuery": "ocean"
}
```

***

### ⚙️ Get Product Tags

```
POST https://b2b-solution-public-api.bsscommerce.com/api/v1/product/get-tags
```

```json
{
  "domain": "abc.myshopify.com",
  "accessKey": "xxx"
}
```

***

### 📄 Get Products by Tags

```
POST https://b2b-solution-public-api.bsscommerce.com/api/v1/product/get-by-tags
```

* `"operation": "AND"` → all tags must match
* `"operation": "OR"` → any tag matches

***

### 🏆 Get Products by IDs

```
POST https://b2b-solution-public-api.bsscommerce.com/api/v1/product/get-by-ids
```

***

## 👥 Customer Endpoints

### 🙋🏻‍♂️ Search Customers

```
POST https://b2b-solution-public-api.bsscommerce.com/api/v1/customer/search
```

### ✨ Get Customer Tags

```
POST https://b2b-solution-public-api.bsscommerce.com/api/v1/customer/get-tags
```

### 🗂️ Get Customers by IDs

```
POST https://b2b-solution-public-api.bsscommerce.com/api/v1/customer/get-by-ids
```

### 📍 Get Customers by Tags

```
POST https://b2b-solution-public-api.bsscommerce.com/api/v1/customer/get-by-tags
```

> `"operation": "AND"` → must contain all tags\
> `"operation": "OR"` → contain any tag

***

## 📚 Collection Endpoints

> *Note: The “Get Collections” endpoint currently returns a `customers` array — behavior is identical to `/customer/search`.*

```
POST https://b2b-solution-public-api.bsscommerce.com/api/v1/customer/search
```

***

## ⚙️ Request Handling Policy

* Requests are processed **one at a time**.
* A new request starts only after the previous one completes.
* If a **server error** occurs, please wait up to **3 minutes** before retrying.
