Shipping Rules

Assign a service to each store order automatically, with no one choosing by hand.

When an order arrives from a connected store, something has to decide how it ships. Shipping rules make that decision for you.

The operations — list the services a shop can offer, create rules, apply them to an order — are in Shipping Rules.

How a rule works

A rule has three parts:

WHEN            this order matches        type + country + range
THEN use        this service              option_1
IF IT CAN'T     fall back to these        option_2, option_3

Five types, and you choose one criterion per shop:

typeApplies whenUses min/max
FixedAlways, within its country and zone—
MoneyThe order value falls in a range✅ currency in measurement
WeightThe order weight falls in a range✅ weight unit in measurement
ProductThe order contains the products in products—
MethodThe store's shipping method matches methods—
⚠️

You can have several rules of the same type, but you cannot mix types on one shop.

Decide the criterion that fits the shop — weight, order value, product or the store's own method — and build all its rules on that one.

Create a rule

API reference → Create shipping rule

curl -X POST https://queries.test.envia.com/config/1204/shipping-rules \
  -H "Authorization: Bearer $ENVIA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Pesados a provincia",
    "country_code": "MX",
    "international": false,
    "type": "Weight",
    "measurement": "KG",
    "min": 20,
    "max": 70,
    "option_1": 45,
    "option_2": 12,
    "priority": true
  }'

Required: name, country_code, international, type, measurement, option_1.

measurement is required even when it does not apply. Send null for Fixed, Product and Method.

Where the service ids come from

option_1, option_2 and option_3 are service ids. Read them from GET /default-shop-services/{shop_id} — they vary by shop, country and whether the shipment is international. Do not hard-code them.

Priority or cheapest

priority decides how the three options are used:

true (default)Use them in order. option_1 first, and only fall back if it cannot serve the route
falsePick the cheapest of the three

Rules by product or by store method

For type: Product, list what triggers the rule:

{
  "type": "Product",
  "measurement": null,
  "products": [
    { "ecart_product_id": "77120", "ecart_variant_id": "77120-L" }
  ],
  "option_1": 45
}

For type: Method, map the store's own shipping method names to each option:

{
  "type": "Method",
  "measurement": null,
  "methods": {
    "options_name_1": ["Express", "Envío rápido"],
    "options_name_2": ["Estándar"]
  },
  "option_1": 45,
  "option_2": 12
}

The names must match what the store sends at checkout, exactly.

Narrowing a rule to a zone

shop_shipping_zone_id restricts the rule to a state or city. Leave it null and it applies to the whole country.

See what the rules decide

API reference → Apply the rules to an order

Before trusting them in production, ask what they would pick for a real order:

curl -X POST \
  https://queries.test.envia.com/config/1204/shipping-rules/select/ORD-88213 \
  -H "Authorization: Bearer $ENVIA_TOKEN"

No request body, and nothing changes. Envia reads the order from the store, works out whether it is domestic or international, applies the matching rule and answers which service it chose. The order is not modified and no label is created.

Endpoints

Next steps


Did this page help you?