Re: Shopify Discounts Query

Solved

Shopify Discounts Query

sandeepks23
Shopify Partner
41 0 5

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 5

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 5

Still got the same issue after reinstalling again