How can I get a product's price for each market with GraphQL?

Solved

How can I get a product's price for each market with GraphQL?

Kushalk
Shopify Partner
2 1 0

Using a product identifier like the product id or handle, I am trying to use the GraphQL API to get a product’s price for all market. I am able to get information like the product’s name in various markets using the product->translations(). Is there any similar strategy for getting a product’s price from each market?


I was able to get the pricesList for a market with this GraphQL API query:

{
  markets(first: 10) {
    edges {
      node {
        priceList {
          prices(first:10) {
            edges {
              node {
                price {
                  amount
                  currencyCode
                }
                variant {
                  id
                  product {
                    handle
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

 

From the priceList I can get the prices for all products in a market. However, in order to get the market price for a specific product, I would need to query the entire market’s priceList which seems very inefficient. Is there a simpler way of doing this?

Accepted Solution (1)

Kushalk
Shopify Partner
2 1 0

This is an accepted solution.

I was able to figure out a way to accomplish my goal. I wanted to get market specific product data for each market that a product was in.

 

I first got the markets data with a GraphQL API call like this:

{
  markets(first: 10, after: $cursor) {
    pageInfo {
      hasNextPage
      endCursor
    }
    edges {
      node {
        name
        webPresence {
          rootUrls {
            url
            locale
          }
        }
      }
    }
  }
}

 

Since I now have the URL for each market, I was able to get the product data by using this Product Ajax API.

So your final API call would be something like this: `{market_webPresence_url}/products/{handle}.js`.

View solution in original post

Replies 2 (2)

Kushalk
Shopify Partner
2 1 0

This is an accepted solution.

I was able to figure out a way to accomplish my goal. I wanted to get market specific product data for each market that a product was in.

 

I first got the markets data with a GraphQL API call like this:

{
  markets(first: 10, after: $cursor) {
    pageInfo {
      hasNextPage
      endCursor
    }
    edges {
      node {
        name
        webPresence {
          rootUrls {
            url
            locale
          }
        }
      }
    }
  }
}

 

Since I now have the URL for each market, I was able to get the product data by using this Product Ajax API.

So your final API call would be something like this: `{market_webPresence_url}/products/{handle}.js`.

Kumar2573
Shopify Partner
172 8 23

Hi 

I have implemented each markets pricelist using grapghql admin api in php.

Shopify Certified Developer Profile - https://www.credly.com/badges/1733d05c-2a88-490a-aef5-b01baf3b94ce/public_url
Expert Shopify Plus & shopify Developer & Theme customizer
- If the problem is solved remember to click to Accept Solution
- Press Like ?? if the answer was helpful
- Still, Facing issue, Reach out to me Email :- [email protected] | Skype :- jitendra2573_1
- Direct Hire me :- Direct Contact me