Step 6. Set the delivery method
The setShippingMethodsOnCart
mutation defines the delivery methods for your order. It requires these input parameters:
cart_id
carrier_code
method_code
{ CART_ID }
is the unique shopping cart ID from Step 2. Create empty cart.
The carrier_code
and method_code
values come from the response of the setShippingAddressesOnCart
mutation on the Set the shipping address step.
For logged-in customers, send the customer's authorization token in the Authorization
parameter of the header. See Authorization tokens for more information.
Request:
The following mutation assigns Table Rate method.
Copied to your clipboardmutation {setShippingMethodsOnCart(input: {cart_id: "{ CART_ID }"shipping_methods: [{carrier_code: "tablerate"method_code: "bestway"}]}) {cart {shipping_addresses {selected_shipping_method {carrier_codemethod_codecarrier_titlemethod_title}}}}}
Response:
Copied to your clipboard{"data": {"setShippingMethodsOnCart": {"cart": {"shipping_addresses": [{"selected_shipping_method": {"carrier_code": "tablerate","method_code": "bestway","carrier_title": "Best Way","method_title": "Table Rate"}}]}}}}
Verify this step
Sign in as a customer to the website using the email
john.doe@example.com
and passwordb1b2b3l@w+
.Go to Checkout.
The selected delivery method is displayed in the Shipping Methods section on the Shipping step.