Description
Preconditions (*)
- Magento 2.4.2
Steps to reproduce (*)
- Create Dropdown type Product Attribute with values required yes. Ex: M, L, XL
- Reindex and flush cach
- POST request to
/rest/all/V1/products/attributes/{attributeCode}/options
Paylod:
{ "option": { "label": "XXL", "value": "", "sort_order": 0, "is_default": false, "store_labels": [ { "store_id": 1, "label": "XXL" } ] } }
Magento will return option ID as a response ('220' in my case).
-
If you try to call the API again with the same data, you should get the exception message, as you did, because you're trying to create duplicate labels.
-
But, if you try to create new label which is the same as option ID you received in the previous request, Magento returns an exception, because it compares existing option IDs for the attribute with the label that has been posted:
Payload:
{ "option": { "label": "220", "value": "", "sort_order": 0, "is_default": false, "store_labels": [ { "store_id": 1, "label": "220" } ] } }
Instead of creating new attribute label, which would be expected behavior, Magento responds that the option already exist, which is incorrect:
{ "message": "Admin store attribute option label "%1" is already exists.", "parameters": [ "220" ], }
This is cased by comparing received option label with IDs of already existing options for that attribute, as @cfarnleitner already pointed out.
This doesn't happen from the admin UI because admin controller is using different logic than the API endpoint.
Expected result (*)
API should be working fine with 200 success code.
Note: There is no issue if added from admin UI
Actual result (*)
{ "message": "Admin store attribute option label "%1" is already exists.", "parameters": [ "220" ], }
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.