I’m trying to execute a query of priceRule to get the discount codes in my store. The query works fine in GraphiQL in my admin page, however, in GraphiQL IDE I get this error: DiscountCodeSortKeys isn’t a defined input type (on $code) . Is it because of the permissions offered by Storefront? And is there a possibility to get a list of the discount codes?
What info are you trying to get? A list of discount codes on your Store? You wouldn’t be able to accomplish this using the Storefront API. You would need to use the Admin API (REST or GraphQL). If you can provide more specifics I can share an example call.
DiscountApplications in the Storefront API that you mentioned is only an object that exists on a specific Checkout. This lets you see the code applied to that checkout.
Unfortunately via GraphQL there isn’t a great way to reverse lookup by code. You can look at all existing codes and parse the results to find the code with a simple GraphQL query similar to:
Yes, that query works in GraphiQl app in my admin page, however, it doesn’t work in my Javascript code linked to the liquid page in the templates folder, because the priceRule field does not exist in the Storefront API.
I tried the “REST” solution that you suggested but it asks for administration information (username and password) which is not good for me because this is a public page in the store.
Is there a similar method to get the discount codes or at least avoid the username and password input?
No, you cannot get access to discount codes without being authorized to use
the admin API on that shop. You can see how that would be a problem if
anyone was able to access it.