updateCartBuyerIdentity mutation can be used to attach shipping information to a cart, which will then let you retrieve shipping options and the final cart cost.12345678910111213141516171819202122232425262728293031323334353637383940mutation AttachBuyerIdentity { updateCartBuyerIdentity( input: { # NOTE: Replace this value with your own cart's identifier! id: "TgDZ0GvuqZkVlmdhm94f" buyerIdentity: { firstName: "John" lastName: "Doe" email: "john@rye.com" address1: "1460 Broadway" city: "New York City" provinceCode: "NY" countryCode: US postalCode: "10036" } } ) { cart { id cost { isEstimated shipping { currency displayValue value } total { currency displayValue value } } } errors { code message } } }
deleteCartItems and our cart price dropped below that threshold, we would see a non-zero shipping price.errors field on the cart. You can see what this looks like if we pass an invalid postal code inside our input:123456789101112131415161718192021222324252627mutation AttachBuyerIdentity { updateCartBuyerIdentity( input: { # NOTE: Replace this value with your own cart's identifier! id: "TgDZ0GvuqZkVlmdhm94f" buyerIdentity: { firstName: "John" lastName: "Doe" email: "john@rye.com" address1: "1460 Broadway" city: "New York City" provinceCode: "NY" countryCode: US postalCode: "1991559" } } ) { cart { id } errors { code message } } }
CartErrorCode reference page. Error codes prefixed with BUYER_IDENTITY_ indicate an issue with the provided buyer identity, and if these are not resolved then checkout will fail.updateCartBuyerIdentity request:1234567891011121314151617181920212223242526272829303132mutation AttachBuyerIdentity { updateCartBuyerIdentity( input: { # ... } ) { cart { id # ... stores { ... on AmazonStore { store offer { shippingMethods { id label price { currency displayValue value } } } } } } errors { code message } } }
store and offer fields on the AmazonStore object. If you are ordering from Shopify, then these fields also exist on the ShopifyStore object with a very similar structure.store field acts as a unique identifier for the store. A single Rye cart can contain cart items from multiple merchants at the same time, and the stores list lets you see how your cart items are broken up by store. In the case of a multi-store cart, each store will have its own shipping options available. Our example cart only needs to deal with a single store, which makes things slightly easier.offer field is available through any API operation that returns a cart, including getCart. This is helpful if you forgot to request offer when you first attached buyer identity information.shippingMethods from a Shopify store, it may be because both of the following conditions are met:updateCartSelectedShippingOptions mutation can be used to explicitly select your shopper's preferred shipping method.1234567891011121314151617181920mutation SelectShippingOption { updateCartSelectedShippingOptions( input: { # NOTE: Replace all of these values with ones from your cart! id: "TgDZ0GvuqZkVlmdhm94f" shippingOptions: [{ store: "amazon" shippingId: "0-Default shipping method" }] } ) { cart { id } errors { code message } } }
Cart object here; we are not only limited to the id field. Note that the shippingOptions input is a list of shipping options; this is to support passing shipping options for multiple stores in a single API call. The store field inside a shippingOptions entry must align with the store value on the corresponding AmazonStore or ShopifyStore objects.BuyerIdentityInput type are explicitly marked as being required, it is a good idea to provide as many fields as you can as we do run additional validation on these fields beyond what our schema advertises.provinceCode is a required field when shipping to the USA but can be safely omitted when shipping to an address in the UK. In general, our address validation logic is aligned with local expectations around the formatting of addresses.email you provide here will receive order update emails from Shopify. This can be inconvenient in cases where you are applying a mark up.phone value, if provided, must be a valid phone number in E.164 format.provinceCode value should generally be a valid ISO 3166-2 code without the country code prefix. For instance, AUK would represent the "Auckland" region of New Zealand. Providing the official code for the region is the most accurate method for specifying the delivery zone.Auckland) and our API will attempt to match that name to the correct code automatically.lastName field is required, as some marketplaces we support ordering from also require this field. In some parts of the world, people do not have last names which can cause problems. Our recommendation in this case is to set lastName to the name of your company to work around this marketplace limitation.firstName: "John", lastName: "Rye".