Prompt
How do I show shipping options before checkout using an API?
Latest observation
Nov 4, 2026
OpenAI APIWeb search: off
To show shipping options before checkout, you typically use a shipping rates / quotes API tied to the customer’s cart and destination address.
Typical flow
-
Collect cart details
- Items, quantities, weight, dimensions, value, origin warehouse, etc.
-
Collect destination address
- Country, postal code, city, state, etc.
-
Call the shipping rates API
- Send the cart + destination + service preferences.
- The API returns available shipping methods, prices, and delivery estimates.
-
Display options to the customer
- Example: Standard, Express, Overnight
-
Store the selected option
- Save the chosen rate/shipping method to the cart or session.
-
Use the selected option at checkout
- Pass the chosen shipping method into the order creation request.
Example request
POST /shipping/rates
Content-Type: application/json
{
"destination": {
"country": "US",
"postal_code": "94107",
"state": "CA",
"city": "San Francisco"
},
"cart": {
"items": [
{
"sku": "TSHIRT-001",
"quantity": 2,
"weight": 0.5,
"dimensions": { "length": 10, "width": 8, "height": 1 }
}
],
"subtotal": 49.98
}
}
Example response
{
"rates": [
{
"id": "rate_standard",
"name": "Standard Shipping",
"price": 5.99,
"currency": "USD",
"eta": "3-5 business days"
},
{
"id": "rate_express",
"name": "Express Shipping",
"price": 12.99,
"currency": "USD",
"eta": "1-2 business days"
}
]
}
Frontend UX pattern
- Ask for ZIP/postal code early in the cart page or shipping step.
- Fetch rates as soon as the address is valid.
- Show a loading state while rates are retrieved.
- Let users select one option before they hit checkout.
Important considerations
- Use real-time rates if carrier pricing changes often.
- Cache briefly to reduce API calls, but refresh when address/cart changes.
- Handle unavailable destinations gracefully.
- Include package rules like free shipping thresholds or restrictions.
- Round-trip validation: make sure the rate chosen before checkout is still valid when the order is placed.
If you want, I can give you:
- a generic REST API design
- an example using Stripe, Shopify, Shippo, EasyPost, or UPS/FedEx
- a frontend + backend implementation example in Node, Python, or PHP