Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Shopify Discounts Query

Solved

Shopify Discounts Query

sandeepks23
Shopify Partner
41 0 6

Is there any way to fetch all the discounts of a store both automatic and discount codes using a single query?

Accepted Solution (1)

Andrei_Kuchuk
Shopify Partner
44 5 14

This is an accepted solution.

Hi @sandeepks23 

For REST requests unfortunately not. The single way that I found is a two steps request.
The first request is to all price_rules and then to all discount codes inside each rule.

But graphQL request it is potentially possible.
But I don't dive deep into graphQL priceRules api.
There is nothing about discount codes in the docs https://shopify.dev/api/admin-graphql/2021-10/queries/priceRules 😞

Andrei Kuchuk, Lead Shopify developer at SpiralScout

Cooperation email: andrey.kuhcuk@spiralscout.com

View solution in original post

Replies 4 (4)

Andrei_Kuchuk
Shopify Partner
44 5 14

This is an accepted solution.

Hi @sandeepks23 

For REST requests unfortunately not. The single way that I found is a two steps request.
The first request is to all price_rules and then to all discount codes inside each rule.

But graphQL request it is potentially possible.
But I don't dive deep into graphQL priceRules api.
There is nothing about discount codes in the docs https://shopify.dev/api/admin-graphql/2021-10/queries/priceRules 😞

Andrei Kuchuk, Lead Shopify developer at SpiralScout

Cooperation email: andrey.kuhcuk@spiralscout.com
sandeepks23
Shopify Partner
41 0 6

Thanks for that. But when I tried to execute these queries I got an error as "This app is not approved to access the PriceRule object". But in our app we have given the "read_price_rules" in access scope.

Andrei_Kuchuk
Shopify Partner
44 5 14

You might need to reauthenticate/reinstall app after changing scopes

Andrei Kuchuk, Lead Shopify developer at SpiralScout

Cooperation email: andrey.kuhcuk@spiralscout.com
sandeepks23
Shopify Partner
41 0 6

Still got the same issue after reinstalling again