Prompt
How do I make checkout show live shipping options from an API?
Latest observation
To make checkout show live shipping options from an API, the general pattern is:
-
Collect shipment details in checkout
You need enough info to quote shipping:- destination country / postal code
- package weight / dimensions
- cart contents
- origin warehouse/location
- shipping speed preferences, if any
-
Call your shipping-rate API when checkout data changes
When the customer enters or changes address/cart details, your frontend or backend sends a request to your shipping provider or your own rate service. -
Return formatted shipping methods to checkout
The API response should include options like:- carrier/service name
- price
- estimated delivery date/range
- delivery speed
- any restrictions or notes
-
Render those options as selectable shipping methods
Show them as radio buttons, cards, dropdown options, etc. -
Recalculate totals when one is selected
Add the chosen shipping cost to the order total. -
Revalidate at order placement
Shipping quotes can change, so validate the selected option again before finalizing payment/order creation.
Typical flow
Frontend
- User enters shipping address
- Frontend sends:
{ "country": "US", "postal_code": "94107", "items": [ { "sku": "ABC123", "qty": 2, "weight": 1.2 } ] } - Backend returns:
{ "options": [ { "id": "ground", "label": "Ground", "price": 9.99, "eta": "3-5 days" }, { "id": "express", "label": "Express", "price": 19.99, "eta": "1-2 days" } ] }
Checkout UI
- Display options
- User picks one
- Total updates immediately
Important implementation notes
1. Prefer backend calls over direct client calls
If the shipping API requires:
- secret keys
- rate limits
- custom business rules
then call it from your server, not the browser.
2. Debounce address changes
If you fetch rates on every keystroke, you'll spam the API.
Trigger requests when:
- postal code is complete
- address blur event happens
- user clicks “Get shipping rates”
3. Cache rates briefly
Shipping rates usually don’t need millisecond precision. Cache for a short time:
- 1–10 minutes depending on your business
4. Handle failures gracefully
If the API fails:
- show “Unable to calculate shipping right now”
- offer fallback rates if possible
- let the user retry
5. Validate before payment
The selected rate may expire or change. Re-check:
- availability
- price
- delivery window
If you’re using a platform checkout
Shopify
You may need:
- a carrier-calculated shipping integration
- a shipping app or custom app
- in some cases, Shopify Functions / delivery customization, depending on checkout setup
WooCommerce
Use:
- a custom shipping method plugin
woocommerce_package_ratesfilter- or a live shipping plugin integration
Magento / Adobe Commerce
Use:
- a custom shipping carrier module
- rate collector logic
Custom checkout
Implement:
GET /shipping-rates- frontend shipping selector
- server-side order validation
Simple backend example
Node/Express
app.post('/api/shipping-rates', async (req, res) => {
const { country, postal_code, items } = req.body;
// Validate input
if (!country || !postal_code || !Array.isArray(items)) {
return res.status(400).json({ error: 'Invalid request' });
}
// Call shipping provider API here
const rates = [
{ id: 'standard', label: 'Standard Shipping', price: 8.99, eta: '3-5 business days' },
{ id: 'express', label: 'Express Shipping', price: 18.99, eta: '1-2 business days' }
];
res.json({ options: rates });
});
Frontend example
async function loadShippingRates(address, items) {
const res = await fetch('/api/shipping-rates', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ ...address, items })
});
return await res.json();
}
If you want, I can show you how to do this for a specific stack like Shopify, WooCommerce, Stripe Checkout, Magento, or a custom React/Node checkout.