How can I filter discounts by title using REST or GraphQL APIs?

I want to return discounts based on title given as an input from the user. That is for example if a user input “flat” then it should return all the discounts having “flat” in their titles (eg. FLAT50OFF,FLAT100). So is their any way I can implement this using REST or GraphQL admin APIs. I have seen a query like this requirement for products:

products(first: 10, query: "title:*searched_text*")

So is there anything like this for discounts.

The Shopify GraphQL Admin API does not currently have a way to query for discounts by title. However, you may be able to accomplish this using the REST Admin API.

There is no specific code example that I can provide since this would be dependent on your particular implementation. However, you may be able to use the REST Admin API’s List Discounts endpoint to accomplish this: https://help.shopify.com/api/reference/discount#list-discounts You would need to make a GET request to this endpoint, passing in the title as a query parameter. The response would return a list of all discounts that match the title.

The request would typically look like this: GET /admin/api/2020-04/discounts.json?title=flat

I dont know whether this API is active or not. I got an error as {‘errors’: ‘Not Found’} and also the document link you shared is also not found.

Hey sorry about that I pulled that link from an old bookmark. I took a look at the REST API for the discount codes at https://shopify.dev/api/admin-rest/2022-07/resources/discountcode. It may take some parsing but the requests are there as long as you can retrieve the discount codes you can use the json to do the parsing with the responses. I could set it up for you if you’d like just give me a call and we could get started within the hour. Good Luck!

But this retrieves only discount codes right. How about if I want to retrieve automatic discounts also?

discount_type should work for automatic discounts.

OK, Thanks.