Skip to content

Set Shipping Method

Select a shipping method for the order.

Endpoint

POST /api/shop/checkout-shipping-methods

Request Headers

HeaderRequiredDescription
Content-TypeYesapplication/json
X-STOREFRONT-KEYYesYour storefront API key
AuthorizationYesThe cart's own token as a Bearer token, or a logged-in customer's token.

Request Body

json
{
  "shippingMethod": "flatrate_flatrate"
}
FieldTypeRequiredDescription
shippingMethodstringYesThe method value of the chosen rate from Get Shipping Methods, e.g. flatrate_flatrate.

There is no shippingMethodCode field. Send the rate's method, not its idflatrate_flatrate_flatrate is the id and is not accepted.

Response Fields (201 Created)

FieldTypeDescription
idstringCart ID.
cartTokenstringThe cart's token, unchanged.
shippingMethodstringThe method now saved on the cart.
successbooleantrue when the method was saved.
messagestringShipping method saved successfully.

The response is a small confirmation object, not the cart. Read the updated totals — shipping now affects the grand total — from Get Cart.

Validation

RuleResult
shippingMethod presentMissing → 500 with Shipping method is required.
A Bearer token identifies the cartOtherwise 401 Authentication token is required.
An address is saved on the cartRates cannot be listed without one, so there is nothing valid to send.

Use Cases

  • Shipping step of checkout — post the method from the rate the shopper picked, then move on to Set Payment Method.
  • Change of mind — posting a different method replaces the saved one; there is no separate clear call.

Best Practices

  • Take the value from the rate list — hardcoding a method code breaks as soon as the store enables or renames a carrier.
  • Fetch the cart afterwards to show the new total — this response carries no totals.
  • Re-run the shipping step after an address change — the saved method may no longer be offered for the new destination.

Released under the MIT License.