Accurate Shopify Shipping Rates with BinSolver

| Integration

The default shipping logic in most e-commerce platforms is simple: sum the weights. However, carriers don't charge by weight alone. They charge by size.

If you sell pillows or large lightweight items, "weight-based" shipping will drastically undercharge your customers. To fix this, you need box-aware shipping rates.


The Architecture

Shopify's CarrierService API allows you to hijack the checkout process. When a customer reaches the shipping step, Shopify sends the cart contents to your endpoint.

Shopify Checkout
Your API (Worker)
BinSolver API

Step 1: The Packing Request

Instead of guessing, your API sends the cart items to BinSolver. We check if the items can nest inside each other, if they need specific rotations, or if they require multiple boxes.

// Cloudflare Worker / Next.js API Route
export async function POST(req) {
  const shopifyPayload = await req.json();
  const { items } = shopifyPayload.rate;

  // 1. Map Shopify line items to BinSolver items
  const solverItems = items.map(item => ({
    id: item.sku,
    w: item.width,
    h: item.height,
    d: item.depth,
    weight: item.grams,
    quantity: item.quantity
  }));

  // 2. Get optimal packing from BinSolver
  const packing = await fetch('https://api.binsolver.com/pack', {
    method: 'POST',
    headers: { 'x-api-key': ENV.BINSOLVER_KEY },
    body: JSON.stringify({
      items: solverItems,
      bins: MY_WAREHOUSE_BOXES,
      objective: "minCost"
    })
  }).then(r => r.json());

  // 3. Use packed dimensions to get Real-Time Carrier Rates
  // (Integration with EasyPost / ShipStation / FedEx API)
  const rates = await getCarrierRates(packing.bins);

  return Response.json({ rates });
}

Step 2: Getting the Quote

BinSolver returns the exact list of boxes needed. You then send those specific box dimensions to FedEx, UPS, or USPS API.

The Result: The price the customer sees at checkout matches the label you print in the warehouse. No more surprises.

Why Custom Apps?

While there are "Box Packing" apps on the App Store, building a custom integration (or using a headless approach) gives you full control. You can define custom business rules like:

  • "Always ship glass items in double-walled boxes."
  • "Never put food and chemicals in the same package."
  • "If it fits in a flat-rate envelope, always choose that."

Ready to Build?

Check out our API documentation to see the full list of constraints you can enforce, from hazmat rules to stacking limits.