Support international pricing on storefronts
The prices displayed in a storefront can vary based on a customer's location. This guide shows you how to use the Storefront API to query international prices for products and orders, and explicitly set the context of a cart.
Anchor to RequirementsRequirements
- You've completed the Getting started with the Storefront API guide.
- You're familiar with querying products and collections.
- You've completed the Getting started with the Storefront API guide.
- You've set up international pricing in your store.
- You're familiar with the concepts introduced in the cart guide.
- Your Headless channel or custom app has the
unauthenticated_read_product_listings
,unauthenticated_read_customers
andunauthenticated_write_checkouts
access scopes. Learn how to configure your access scopes using Shopify CLI. Learn how to request permissions for Headless channels.
- Your Headless channel or custom app has the
unauthenticated_read_selling_plans
access scopes. Learn how to request permissions for Headless channels.
- You need to manually enable each country’s currency in a Shopify store's payment settings before you can create a query with different country contexts. Any queries for countries that aren't enabled will default to the store currency.
- You're using API version 2022-07 or higher.
Anchor to Step 1: Make queriesStep 1: Make queries
You can use the Storefront API to make the following queries:
- Query available countries and currencies
- Query product prices
- Query price ranges for products
- Query customer orders
Anchor to Query available countries and currenciesQuery available countries and currencies
To retrieve a list of available countries and corresponding currencies for a shop, you can query the localization
field on QueryRoot
. Specify a GraphQL directive called @inContext
to get the current country's information.
Anchor to @inContext directive@in Context directive
A directive provides a way for apps to describe additional options to the GraphQL executor. It lets GraphQL change the result of the query or mutation based on the additional information provided by the directive.
In the Storefront API, the @inContext
directive takes an optional country code argument, and applies this directive to the query or mutation. The following example shows how to retrieve a list of available countries and their corresponding currencies for a shop that's located in France (@inContext(country: FR)
).
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL query
JSON response
Anchor to Query product pricesQuery product prices
To retrieve international prices for products, specify the @inContext(country: countryCode)
directive in your query.
This directive also automatically filters out products that aren't published for the country that's specified in the directive. Merchants determine the products that are published for a given market.
If you don't include the @inContext
directive, then the products that are published for the primary market are returned together, with prices in the shop's currency.
The following example shows how to query the price of the first published product in a storefront within the context of Canada (@inContext(country: CA)
). The response returns the price of the product in Canadian dollars.
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL query
JSON response
Anchor to Query price ranges for productsQuery price ranges for products
To query the price ranges for products, include the priceRange
and compareAtPriceRange
fields in your request.
Within the priceRange
field, you can retrieve the lowest variant's price (minVariantPrice
) and the highest variant's price (maxVariantPrice
). You can also retrieve the compare at price of the product across all variants (compareAtPriceRange
).
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL query
JSON response
Anchor to Query customer ordersQuery customer orders
Order information is returned in the context that it was created. For example, when an app requests the context of France (@inContext(country: FR)
), any previous orders that were created in the United States are returned in USD totals:
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL query
JSON response
Anchor to Step 2: Create a cartStep 2: Create a cart
After you've retrieved data about the available countries and currencies, products and their prices, and customer orders on a store, you can create a cart.
While queries use the @inContext
directive to contextualize the response from the server, cart uses an explicit buyerIdentity
argument as an input to the mutation that will be persisted. Context within the cart is progressive and can change as customers input their address or additional information.
The buyerIdentity
argument contextualizes product variant prices and assures that all products are published for the given country. You can access product variant prices on a cart using the amount
and compareAtAmount
fields. The country code that's passed into buyerIdentity
contextualizes the estimated cost of the cart.
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL mutation
JSON response
Anchor to Next stepsNext steps
- Learn how to create and update a cart in Shopify with the Storefront API.
- Learn how to manage subscription products by querying selling plans and selling plans groups with the Storefront API.
- Learn how to manage customer accounts with the Storefront API.
- Retrieve metafields with the Storefront API to access additional information from different types of resources.
- Support multiple languages on a storefront with the Storefront API.