A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hello,
I want to fetch the prices in different currencies for the products in my store using the Shopify API.
I managed to find this in the REST API with presentment_prices on product variant. (https://shopify.dev/docs/api/admin-rest/2024-01/resources/product-variant#resource-object) However I want to use the Graph QL api but presentment prices doesn't seem available in the Graph QL api. I did find something called Contextual pricing in the Graph QL api but it seems to have to do with specific quantity discounts so not exactly the same to my undesrstanding. (https://shopify.dev/docs/api/admin-graphql/2024-01/objects/ProductVariantContextualPricing)
Any idea how to fetch presentment price/variant price and compare at price in other currencies using the Graph ql api?
Hey @mannenson,
It sounds like you are looking for the Contextual prices in the Admin API or localised Storefront API prices. There's an International Pricing section in our guide on using Markets that has examples of each.
The ProductContextualPricing object can provide a range of prices for the product's variants, and each productVariant also has it's own contextualPricing field.
Hope that helps!
- James
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Thanks @ShopifyDevSup / James. Facing the same. With the deprecation of the Admin REST API, I'm transitioning to GraphQL for product data fetching. I need to get the localized prices for every market for each product variant - previously possible via single REST API (presentment_currencies). There doesn't seem to be a way to do this with the GraphQL API. The only solution would be separate requests (get the contextual pricing for each market one by one) - which is impractical and inefficient for our systems and Shopify's. Is there a GraphQL strategy for bulk fetching localized prices, or plans to support this use case? If not, can we raise this as a hard request?
@ShopifyDevSup I'm facing the same issue, i need to fetch product prices in all currencies like we did in REST API using presentment-prices in the Headers. But in Graphql API it is impossible to fetch prices in all currencies in one request. The only solution would be separate requests for each market one by one - which is highly inefficient to send 100's of requests to Shopify. Is there a GraphQL strategy for bulk fetching localized prices, or plans to support this use case? If not, can we raise this as a hard request?
Hi @JSegeren and @Saifchaudhry,
I've looked into this a bit further and did some testing on my own store and I can confirm that you can retrieve the price for each currency using the contextualPricing field on the productVariant object, you'll just need to add the contextualPricing field to your query multiple times, each with a different alias, along with an argument for each currency you want to query.
Here's an example I ran on my test store that returns the price for product variants in both CAD and USD.
NOTE: The aliases I used are contextualPricingCA and contextualPricingUS though these aliases are not defined by our API and can be anything you wish to name them as.
{
products(first: 10) {
edges {
node {
variants(first: 10) {
edges {
node {
title
displayName
contextualPricingCA: contextualPricing(context: { country: CA }) {
price {
amount
currencyCode
}
}
contextualPricingUS: contextualPricing(context: { country: US }) {
price {
amount
currencyCode
}
}
}
}
}
}
}
}
}
The contextualPricing context argument can also accept a Company Location ID, so you can also retrieve B2B specific prices as well. This is referenced in the following dev docs:
And here's a Shopify Partners blog article that we have that explains using Aliases with GraphQL further:
I hope this helps, and I hope you have a great day 🙂
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hi @ShopifyDevSup. I faced related issue a month ago.
I used to use the REST API to get prices in different currencies, but I found that the presentment_prices field didn't calculate the price according to Market calculations.
Here is an example of calculating the market price:
But presentment_prices returns the following:
"price": {
"amount": "370.95",
"currency_code": "EUR"
},
I found a ProductVariantContextualPricing object in the GraphQL API, which return the correct prices. I also discovered myself that it is possible to get multiple currencies by adding multiple contextualPricingCountryCode fields, as you wrote in the answer above.
The problem I'm trying to solve right now is whether it's possible to get prices for all countries/markets without having the entire list of country codes.
For context: I'm working with a client that has Markets configured for 62 countries. It has 25,000 products with different variants. It takes 8 hours to get all prices for all countries.
I also have to only request 5 contextual prices at a time because otherwise I exceed Shopify's internal response limit or something because I get this error:
Convermax.Shopify.Exceptions.ApiCallException: 'BulkOperation failed. Status: CREATED. Id: gid://shopify/BulkOperation/*id*'
I work with several Shopify clients and need to index their stores as quickly as possible, so 8 hours for just one store is not acceptable.
I noticed that a request with only 1 contextual price takes about 15 minutes, and a request with 5 at the same time takes about 30 minutes. Therefore, I hope that I will somehow be able to get contextual prices for all countries at once and it will take about 4 hours, but I don’t know how to do this.
Can you help me figure this out?
Hi @VladKomin,
Unfortunately at this time, there is no way to retrieve the localized prices for a product on all markets in a single call. That said, as you mentioned some of your clients have many countries enabled in various markets, you can make a query to retrieve all of the countries used in all enabled markets, then use this list of countries to make the product calls in bulk with the country code in the contextualPricing argument. Here's an example of this query that returns all currencies and regions/countries on all enabled markets.
{
markets(first: 50) {
edges {
node {
name
handle
regions(first: 50){
edges{
node{
id
name
}
}
}
currencySettings {
baseCurrency {
currencyCode
currencyName
}
}
enabled
}
}
}
}
Once you have the list of countries on enabled markets, you can map those with the [ISO 3166 Country Codes](https://www.iso.org/iso-3166-country-codes.html) and use the country codes in the contextualPricing arguments in your Bulk Operation queries.
As for the failed Bulk Operation Queries, we would need more context in the queries created to be able to help troubleshoot further. If you can please confirm that your queries are valid and not failing any of the restrictions listed in our Shopify.dev Documentation: Perform bulk operations with the GraphQL Admin API
If your queries are inline with our Bulk Operation Query restrictions, please do reach out to our Support Team via the Shopify Help Center, with the following information and we can help look into this further after you are authenticated on the store the query is failing on:
- The Bulk Operation ID that failed
- The full HTTP request body and headers (not including any private keys or access tokens)
- The failing call's x-request-id or the full HTTP response body and headers (not including any private keys or access tokens)
I hope this helps, and I hope you have a great day 🙂
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
What a gem of a response, worked perfectly and I expect will suit most users for this question.