# Shipping Rules Guide

Shipping Rules provide ShipStation API with a set of criteria to determine which carrier and service to apply to a shipment. This allows you to automate the selection of carrier and service according to your specific business needs.

If you are new to Shipping Rules, be sure to read our [Introduction to Shipping Rules](/apis/shipengine/docs/shipping/shipping-rules-intro) page.

Currently, you must create your shipping rules in your account dashboard. Once created, each rule will have a shipping rule ID that you can use to automate carrier and service selection when creating shipments or purchasing labels.

For each shipment, ShipStation API will evaluate the rule statements against the shipment details and apply the appropriate `carrier_id` and `service_code` to the shipment for you.

> **NOTICE:**
### Shipping Rules Endpoints Coming Soon
We will sooon be adding a shipping rules endpoint so you can also create rules programmatically. Check back soon for details on using this new endpoint.


## Create a Shipping Rule

To create a shipping rule:

1. Log in to your account dashboard and go to **Shipping Rules**.
![ShipStation API Dashboard Shipping Rules in the side navigation](/assets/dash_sidenav_shippingrules.4c9f94780fc4d7cf57975981dfa2a5d10f8b561bc0f9a85a507e9ddeef33679c.31478e40.png)
2. Click the **Create rule** button.
3. Choose the type of rule you wish to create, condition or service group.
![Select shipping rule type popup](/assets/dash_shippingrules_selectruletype.7485fffe2bae30c25b693b8a147a31fb2f43abf547076af630a321aefd5afcac.31478e40.png)
4. Enter a name for your rule (each rule requires a unique name).
5. Create the statements with the conditions you require (see below sections for details on creating each type of rule).


### Condition-based Rules

With condition-based rules, you define explicit sets of conditions the shipment must meet for the service defined in the statement to be allocated to that shipment.

To create a condition-based rule:

1. Fill in the first condition for Statement 1. ![Shipping rule with first rule statement](/assets/dash_shippingrule_conditionbased_firststatement.3e6bd72ec4c071bd0f6913c0c03cc37c5d80086c2b6c69b4ad753eec95124f99.31478e40.png)
2. Add more conditions if needed. Remember, additional conditions behave as AND statements.
3. Set the carrier and service that should apply to shipments meeting the statement conditions in the **allocate** fields.
4. Add more statements if needed. Remember, additional statements behave as ELSE IF statements. ![Shipping rule with second rule statement](/assets/dash_shippingrule_conditionbased_secondstatement.db1ed592f9f2243dff440ce039c89e567d7b3e860620996e44a7e0add58a411e.31478e40.png)
5. Set the default carrier and service that will apply if the shipment does not meet the conditions for any of the rule statements.
6. Save the rule.


### Service Group Rules

With service group rules, you first create a list of services in a prioritized order. Then, you create "exclusion statements" with conditions that will *exclude* a service from the shipment if the shipment meets the statement conditions.

To create a service group rule:

1. Choose a carrier and select which of that carrier's services to include in your priority list. ![Add services to Service Group shipping rule](/assets/dash_shippingrule_servicegroup_addservices_mrk.4589c2236cb607c9a5fc2a76897f30b89d1670ef8129142b5402a2f4e9678feb.31478e40.png)
2. Click the **Add to list** button to add this set of services to the list.
3. (Optional) Continue to add services to your priority list, a carrier at a time, until you have the full list of services you wish this rule to contiain.
4. Arrange the priority of the services in your list. You can drag and drop the services into the desired order, or use the up/down arrows to adjust the position of a service in the list. ![Move services in priority list for shipping rules](/assets/dash_shippingrules_moveservicesinlist_mrk.fe725df49067156f9bcacd88f9450b20857c4bd0f01fc509c727cb31d0fdb3d6.31478e40.png)
5. Fill in the first condition for Statement 1. ![Service group rule first statement](/assets/dash_shippingrule_servicegroup-firststatement.2c164fccc6cc02da8daf20c18a66995aaf9a779b3dad39b4e45d072f3c524a99.31478e40.png)
6. Add more conditions if needed. Remember, additional conditions behave as AND statements.
7. Choose which services to exclude from shipments that meet the statement conditions.
8. Add more statements if needed. Remember, additional statements behave as ELSE IF statements. ![Service group rule second statement](/assets/dash_shippingrule_servicegroup-secondstatement.37961fe3e70c83d6361884748b74b438bb4fd05abb998d29960419ab88c23592.31478e40.png)
9. Save the rule.


> **Dynamic Ordering**
Service Group Rules can use dynamic ordering (*Cheapest* or *Fastest*) to automatically rank eligible services in real time based on live rate or transit data. Learn about the requirements, USA carrier restrictions, and how it impacts your existing lists: [Configuring "Order Services By" in Service Group Rules](/apis/shipengine/docs/shipping/shipping-rules-configuring-order-services-by).


## Apply Rules to Your Shipments

Once you have created your shipping rules, you will use the `shipping_rule_id` as a path parameter in the dedicated endpoint to purchase labels. For creating shipments, you can still include the `shipping_rule_id` in the shipment object for the [Create Shipment](/apis/shipengine/docs/shipping/create-a-shipment) endpoint.

When purchasing a label with a shipping rule, you must NOT include `carrier_id`, `service_code`, or `shipping_rule_id` in the shipment object — the shipping rule determines these automatically.

ShipStation API will evaluate the shipping rule provided in the request to determine the `carrier_id` and `service_code` that should apply to the shipment. Both will then be included in the corresponding response.

### Create Shipment Example Request

This is an example of the shipment object in a request for [Creating a Shipment](/apis/shipengine/docs/shipping/create-a-shipment).

**POST /v1/shipments/**


```http
POST /v1/shipments HTTP/1.1
Host: api.shipengine.com
API-Key: __YOUR_API_KEY_HERE__
Content-Type: application/json

{
 "shipments": [
  {
   "shipping_rule_id": "se-49",
   "ship_to": {
      "address_line1": "200 Grays Inn Road",
      "city_locality": "London",
      "postal_code": "WC1X 8XZ",
      "country_code": "GB",
      "name": "John Smith",
      "phone": "+44 020 5555 5555",
      "email": "myemail@test.com"
    },
   "ship_from": {
      "address_line1": "Victoria Embankment",
      "city_locality": "London",
      "postal_code": "SW1A 2JF",
      "country_code": "GB",
      "name": "Norman Shaw",
      "phone": "+44 020 7219 4272",
      "email": "youremail@test.com"
    },
   "packages": [
     {
      "package_code": "package",
      "weight": {
        "value": 1.5,
        "unit": "kilogram"
       },
      "dimensions": {
        "height": 6,
        "width": 5,
        "length": 15,
        "unit": "centimeter"
      }
    }
   ]
  }
 ]
}
```

### Purchase Label Example Request

This is an example of the request for [Purchasing a Label](/apis/shipengine/docs/labels/create-a-label) using a shipping rule. The `shipping_rule_id` is passed as a path parameter, and the shipment object must NOT include `carrier_id`, `service_code`, or `shipping_rule_id`.

**POST /v1/labels/shipping_rules/{shipping_rule_id}**


```http
POST /v1/labels/shipping_rules/se-49 HTTP/1.1
Host: api.shipengine.com
API-Key: __YOUR_API_KEY_HERE__
Content-Type: application/json

{
 "shipment": {
   "ship_to": {
      "address_line1": "200 Grays Inn Road",
      "city_locality": "London",
      "postal_code": "WC1X 8XZ",
      "country_code": "GB",
      "name": "John Smith",
      "phone": "+44 020 5555 5555",
      "email": "myemail@test.com"
    },
   "ship_from": {
      "address_line1": "Victoria Embankment",
      "city_locality": "London",
      "postal_code": "SW1A 2JF",
      "country_code": "GB",
      "name": "Norman Shaw",
      "phone": "+44 020 7219 4272",
      "email": "youremail@test.com"
    },
   "packages": [
     {
      "package_code": "package",
      "weight": {
        "value": 1.5,
        "unit": "kilogram"
       },
      "dimensions": {
        "height": 6,
        "width": 5,
        "length": 15,
        "unit": "centimeter"
      }
    }
   ]
  }
}
```

## Available Condition Properties

The following identifiers are currently available to use in your statement conditions:

| Identifier | Value Type | Available Operators | Description |
|  --- | --- | --- | --- |
| To address residential indicator | string | is, is not | Indicates whether this is a residential address. |
| From address residential indicator | string | is, is not | Indicates whether this is a residential address. |
| To country | string | is, is not | The [two-letter ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) country code |
| From country | string | is, is not | The [two-letter ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) country code |
| Warehouse ID | list | in, not in | The warehouse that the shipment is being shipped from |
| To postal code | list | in, not in, starts with | List of postal codes, separated by a comma |
| From postal code | list | in, not in, starts with | List of postal codes, separated by a comma |
| Number of packages | integer | is, is less than, is less or equal to, is greater than, is greater than or equal to | Number of packages of a shipment |
| Total weight | decimal | is, is less than, is less or equal to, is greater than, is greater than or equal to | Weight of a shipment  Available units: Gram, Kilogram, Pound, Ounce |
| Max dimension | decimal | is, is less than, is less or equal to, is greater than, is greater than or equal to | Dimension filter of any of the available dimensions of a shipment `height` `width` `length`  Available units: centimeter, inch |
| Shipment value | decimal | is, is less than, is less or equal to, is greater than, is greater than or equal to | Shipment’s product value sum |