A developer is building a SaaS integration to create discount codes in Shopify and track their sales performance. They’ve identified the correct approach: creating a PriceRule, then a DiscountCode via Admin API endpoints.
Main Challenge:
No direct API endpoint exists to list sales by discount code. The developer discovered an older API version (2023-04) supported this via a Sales report endpoint, but it’s deprecated in the current stable version (2023-07).
Proposed Workaround:
Fetch orders using the Orders API (GET /admin/api/2023-07/orders.json)
Check each order’s discount_codes array for the target code
Use webhooks for real-time order creation updates
Open Questions:
Which order status combination ensures accurate sales totals? (financial_status: paid + fulfillment_status: shipped + status: closed)
Can commissions be managed at the sales level rather than discount code level?
Consensus:
Using financial_status: paid is the safest filter since paid orders aren’t always closed. The solution requires iterating through orders manually—no streamlined alternative currently exists in the Admin or Partner APIs.
Summarized with AI on November 17.
AI used: claude-sonnet-4-5-20250929.
I am looking to integrate a SaaS platform with Shopify stores as a Partner, aiming to be able to create Discount Code as needed then listing Sales by any given Discount Code.
After going through the docs, I understand that the process would go as follow.
Create a PriceRule, using this Admin API endpoint
Create a Discount Code based on a PriceRule, using this other Admin API endpoint
List Sales by a given Discount Code.
My first question, am I on the right path? Is the above process correct?
I am confused on how to achieve point 3, listing Sales of a Discount Code. According to the docs, it should be doable.
But I cannot find any GraphQL or Rest API to satisfy this request, I’ve gone through the Admin and Partners APIs to no avail.
However, I accidentally came across the following Admin API endpoint, under Analytics, to retrieve a Sales report but as you can see, the latest stable version 2023-07 does not support it. Going back to an older version 2023-04 does seem to support this functionality, see here.
So was this endpoint deprecated in the latest Admin API version? Is there an alternative you could point me to?
Is there anything you would suggest I do differently?
For your third point, to list sales by a given discount code, there isn’t a direct endpoint. As an (awkward) workaround, you could indirectly get the information by iterating orders.
E.g.:
GET /admin/api/2023-07/orders.json?status=any
Then, in the response, check in each order if the ‘discount_codes’ array contains the code you’re interested in.
Depending on your specific use case, you might also want to look into webhooks to get real-time updates about order creation, which could be useful in terms of keeping track of when and how often your discount codes are being used.
Thank you for your reply.
I see, I am familiar with this endpoint but I am not sure whether this is something we can rely on, due to the nature of the different orders statuses that we’d need to manage; particularly in the case of refunded, unfulfilled and/or canceled orders.
Do you think a combination of financial_status: paid, fulfillment_status: shipped and status: closed is a guarantee that said orders are completed and therefore I am able to safely compute total discount amount by discount code?
Perhaps here I am taking a step away from the main topic although it goes in the same direction.
Is there a way to manage Commissions on Sales as opposed to Discount Codes?
Paid is probably the safest, since paid orders aren’t always closed.
Is there a way to manage Commissions on Sales as opposed to Discount Codes?
Not an easy way but maybe via adding a hidden cart attribute and retrieving it later - but again, more work for you to look through each order and run calculations.