GraphQL admin API - how to get customer segments from Discount?

begginer1231
Shopify Partner
19 0 1

begginer1231_0-1674787844056.png

Whenever I add customerSelection, the graphql syntax checker says that the field is unavailable.

How can I get the segment that can use the discount code?

 

Thank you

Reply 1 (1)

ShopifyDevSup
Shopify Staff
1322 218 457

Hey @begginer1231, thanks for getting in touch - you should be able to use CustomerSelection as a connection under codeDiscountNodes. You just have to include the typename field in the query, so that it includes the type names for each customer selection like this:

{

codeDiscountNodes(first: 10) {

nodes {

id

codeDiscount {

... on DiscountCodeBasic {

title

customerSelection {

__typename

}

}

}

}

}

}

 

Hope this helps - let us know if we can clarify anything further! 

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