Step 4. Set the shipping address
Use the setShippingAddressesOnCart mutation to set a shipping address.
Add shipping address to the cart
In this step, we use the setShippingAddressesOnCart
mutation to add a shipping address to the cart.
If using guest checkout, run the following example.
If using a logged in customer, send the customer's authorization token in the Authorization
parameter of the header. See Authorization tokens for more information.
Request:
Copied to your clipboardmutation {setShippingAddressesOnCart(input: {cart_id: "{ CART_ID }"shipping_addresses: [{address: {firstname: "John"lastname: "Doe"company: "Company Name"street: ["3320 N Crescent Dr", "Beverly Hills"]city: "Los Angeles"region: "CA"region_id: 12postcode: "90210"country_code: "US"telephone: "123-456-0000"save_in_address_book: false}}]}) {cart {shipping_addresses {firstnamelastnamecompanystreetcityregion {codelabel}postcodetelephonecountry {codelabel}available_shipping_methods{carrier_codecarrier_titlemethod_codemethod_title}}}}}
Response:
setShippingAddressesOnCart
returns the new address details.
Copied to your clipboard{"data": {"setShippingAddressesOnCart": {"cart": {"shipping_addresses": [{"firstname": "John","lastname": "Doe","company": "Company Name","street": ["3320 N Crescent Dr","Beverly Hills"],"city": "Los Angeles","region": {"code": "CA","label": "California"},"postcode": "90210","telephone": "123-456-0000","country": {"code": "US","label": "US"},"available_shipping_methods": [{"carrier_code": "flatrate","carrier_title": "Flat Rate","method_code": "flatrate","method_title": "Fixed"},{"carrier_code": "tablerate","carrier_title": "Best Way","method_code": "bestway","method_title": "Table Rate"}]}]}}}}
{ CART_ID }
is the unique shopping cart ID from Step 2. Create empty cart.
Note the available_shipping_methods
in the response. We will use this information in a later step.
Verify this step
Sign in as a customer to the website using the email
john.doe@example.com
and passwordb1b2b3l@w+
.Go to Checkout.
On the Shipping step, the Shipping Address form contains the address details you entered.