You can retrieve all the Sales rules that are related to the given product by Cart Price Rule Search REST API in Magneto.
Let’s say product SKU “A10001” is associated with two different cart price rules and you want to fetch a list of all the sales rules that are associated with the given SKU.
Magento native supports Cart Rule Search Rest API which will be helpful to fetch products associated with cart rules.
Action: GET
URL: <BASE_URL>/rest/<storeCode>/V1/salesRules/search/
(URL: https://magento245.test/rest/default/V1/salesRules/search/?searchCriteria[filterGroups][0][filters][0][conditionType]=like&searchCriteria[filterGroups][0][filters][0][field]=actions_serialized&searchCriteria[filterGroups][0][filters][0][value]=%25<SKU>%25&searchCriteria[filterGroups][0][filters][1][conditionType]=like&searchCriteria[filterGroups][0][filters][1][field]=conditions_serialized&searchCriteria[filterGroups][0][filters][1][value]=%25<SKU>%25
)
HEADER: Authorization Bearer <ADMIN TOKEN>
Parameters:
searchCriteria[filterGroups][][filters][][conditionType]
searchCriteria[filterGroups][][filters][][field]
searchCriteria[filterGroups][][filters][][value]
You need to pass specific values to the above parameters.
- conditionType will be a `like` operator to fetch product-related data. (The value will be SQL wildcard characters when a like operator is used.)
- field will be actions_serialized and conditions_serialized.
- value will be your product SKU.
While you use conditionType parameter value as the “like” operator, you have to pass SQL wildcard characters, the % wildcard format is the %25.
If you want to search item SKU `A10001` conditionType parameter value will be like, %25A10001%25.
The Rest API URL to search SKU A10001,
https://magento245.test/rest/default/V1/salesRules/search/?searchCriteria[filterGroups][0][filters][0][conditionType]=like&searchCriteria[filterGroups][0][filters][0][field]=actions_serialized&searchCriteria[filterGroups][0][filters][0][value]=%25A10001%25&searchCriteria[filterGroups][0][filters][1][conditionType]=like&searchCriteria[filterGroups][0][filters][1][field]=conditions_serialized&searchCriteria[filterGroups][0][filters][1][value]=%25A10001%25
While you run the Rest API, you will get a response array that contains a list of sales rules associated with the given SKU.