How to retrieve list of markets to which a product has been published using Shopify Admin GraphQL?

How to retrieve list of markets to which a product has been published using Shopify Admin GraphQL?

sudarshan
Shopify Partner
6 0 0

I am trying to get the list of the markets that a product is assigned to GraphQL. For example, in the following example I need to able to retrieve that "Gift card" product is assigned to "International" and "Primary market"

sudarshan_1-1707141845088.png

 

Replies 7 (7)

Liam
Shopify Staff
2846 311 811

Hi Sudarshan,

 

For looking into this, there doesn't seem to be a specific  markets related field on the product object, but I've asked the markets product team for the best way to get this info via graphQL. 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me 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

Nexzer
Shopify Partner
9 0 3

Hi @Liam

Do you have an answer for this?

Nexzer
Shopify Partner
9 0 3

Hi @sudarshan 

Did you end up figuring out a way to do this?

ShopifyDevSup
Shopify Staff
1453 238 498

Hi @sudarshan and @Nexzer,

You can retrieve a list of markets that a product is published in with the Product or Products query using the ResourcePublicationV2 connector to access the MarketCatalog connected to each of the product's publications. Here's an example query that will display the Market names for a specific product:


{
 product(id: "gid://shopify/Product/1234567890") {
   resourcePublicationsV2(first: 50, catalogType: MARKET){
       edges{
           node{
               publication{
                   id
                   catalog{
                       title
                       ... on MarketCatalog{
                           markets(first: 50){
                               edges{
                                   node{
                                       name
                                       handle
                                   }
                               }
                           }
                       }
                   }
               }
           }
       }
   }
 }
}

And here's a list of relevant Shopify.dev references for the resources used in this query:
 

 

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

DarianBia
Shopify Partner
6 0 0

Is there a way to get access to this information via the storefront API? The main use case is that a product is being displayed/returned to a customer when it is restricted to a certain market. So I need to have the ability to check which markets this product is available in before displaying it. Thank you!

Creator of Checkout Plus - A Shopify App that allows merchants to customize their Checkout
To learn more visit Checkout Plus
ShopifyDevSup
Shopify Staff
1453 238 498

Hi @DarianBia 

Publications and Markets are only accessible from the Admin API at this time. However you can accomplish what you are looking for on the Storefront API with @incontext directives on the product queries setting the country the customer is shopping from so it will only return data relevant to that Market.

For example if you make the following query, it will only return products that are published and available for customers in Great Britain.

query Products @inContext(country: GB) {
 woolSweater: product(handle: "wool-sweater") {
   title
 }
 alarmClock: product(handle: "alarm-clock") {
   title
 }
 products(first: 2) {
   nodes {
     title
   }
 }
}

And in this response you can see that only the Wool Sweater product is published on this market:

{
 "woolSweater": {
   "title": "Wool sweater"
 },
 "alarmClock": null,
 "products": {
   "nodes": [
     {
       "title": "Wool sweater"
     }
   ]
 }
}

The query and response provided above are listed as as an example in the product query resource in the Shopify.dev documentation. Additionally if you are using the Customer Account API, you can pass a BuyerInput into the @incontext directive for a logged in customer, to retrieve data that is relevant for that customer, either the Market they're shopping from, or the Company if they're a B2B customer. Here's some additional documentation and guides to help you with making contextualized queries to retrieve market specific data.
 

 

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

DarianBia
Shopify Partner
6 0 0

This helped a ton! Thank you 🙂

Creator of Checkout Plus - A Shopify App that allows merchants to customize their Checkout
To learn more visit Checkout Plus