Magento 2 SalesRule API: Unmasking the Mystery of the `product_ids` Field

The Case of the Missing `product_ids` in Magento 2 SalesRule API

In the complex world of Magento 2 development, encountering API inconsistencies can be a common challenge. A recent GitHub issue (#41002), reported by aminakhyat, sheds light on a peculiar case involving the product_ids field within the SalesRule REST API. This field, while prominently documented in the API contract, appears to be a vestige of an unfulfilled feature, never populated by the system and prone to critical errors if manually interacted with.

The issue, reported on Magento Open Source / Adobe Commerce 2.4.x, highlights a significant discrepancy between the API documentation and the actual behavior of the platform, particularly concerning how cart price rules targeting specific products are handled.

Deep Dive into the Problem

The core of the problem lies in the product_ids field of the salesrule entity. Developers would logically expect this field, when querying a cart price rule via GET /rest//V1/salesRules/, to reflect the IDs of products the rule applies to. However, the investigation reveals a different reality:

  • API Discrepancy: For cart price rules created through the Magento Admin panel, even those explicitly targeting specific SKUs (e.g., via "Apply the rule only to cart items matching the following conditions" -> SKU is ), the product_ids field is conspicuously absent from the API response.
  • Database Reality: A direct inspection of the salesrule table confirms that the product_ids column remains NULL. The actual product conditions (like SKU targeting) are stored within the actions_serialized column, specifically under action_condition.

The reporter meticulously detailed the technical breakdown: "No business logic reads or writes the field — no indexer, observer, save-time, or converter code populates the salesrule.product_ids column or consumes its value." It exists in the @api contract and is reflectively (de)serialized by the Web API layer, creating the illusion of its functionality in generated documentation.

Critical Flaw: Incorrect Persistence

Beyond its vestigial nature, the issue uncovers a critical flaw if a client attempts to supply product_ids via POST/PUT API calls. Due to a lack of proper serialization/deserialization, PHP's array-to-string conversion coerces the array of product IDs into the literal string "Array". Consequently, the database stores "Array" in the product_ids text column, leading to data corruption and a subsequent GET request returning "product_ids": "Array"—neither the intended value nor a valid int[] schema.

SELECT rule_id, product_ids, actions_serialized FROM salesrule WHERE rule_id = 

Impact and Proposed Solution

This issue primarily impacts developers and integrators working with the Magento 2 SalesRule API. Relying on or attempting to populate the product_ids field can lead to incorrect assumptions, broken integrations, or even data integrity problems. The actual product targeting logic resides entirely within the serialized conditions.

The proposed fix is to deprecate the getProductIds() and setProductIds() methods on RuleInterface, its Model\Data\Rule implementation, and associated @method annotations. This would involve pointing developers to the rule conditions instead, effectively cleaning up the API contract to reflect its true implementation.

Community Engagement and Severity

As of now, community engagement on this specific issue is minimal, primarily consisting of automated bot comments for triage and Jira synchronization. The issue has been classified with a severity of S3/S4, indicating that it affects non-critical data or functionality, does not force users to employ a workaround, and primarily impacts aesthetics, professional look, or usability rather than core functionality.

Shopping Mover's Takeaway for Developers

For Magento 2 developers and those involved in migrations or custom integrations, this issue serves as an important reminder: always verify API contract details against actual system behavior. When dealing with SalesRules, explicitly rely on the actions_serialized and its contained action_condition for product-specific targeting. The product_ids field, as demonstrated, is unreliable and should be avoided to prevent potential data issues and ensure robust integrations. This highlights the ongoing need for precise API documentation and consistent implementation across e-commerce platforms like Magento.

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools