rest-api icon indicating copy to clipboard operation
rest-api copied to clipboard

Admin REST API cannot create attribute options (select/multiselect) via /api/v1/admin/catalog/attributes

Open DJB-Developer opened this issue 8 months ago • 0 comments

Bug Report

Summary

When using the Bagisto REST API (/api/v1/admin/catalog/attributes) to create a new attribute of type select or multiselect, the options field is completely ignored. The attribute is created successfully, but no options are saved, and the options array in the response is always empty.

Steps to Reproduce

  1. Call the API endpoint /api/v1/admin/catalog/attributes with a POST request.
  2. Use either application/json or multipart/form-data and include an options field with valid option data (see example below).
  3. The attribute is created, but the options are not saved.

Example Request Body

{
  "code": "age_range",
  "type": "select",
  "admin_name": "Age Range",
  "en": {
    "name": "Age Range"
  },
  "fr": {
    "name": "Tranche d'âge"
  },
  "swatch_type": "dropdown",
  "default-null-option": null,
  "options": {
    "option_1": {
      "swatch_value": "#00ff00",
      "sort_order": 1,
      "admin_name": "10 & Above",
      "en": {
        "label": "10 & Above"
      },
      "fr": {
        "label": "10 et plus"
      },
      "nl": {
        "label": "10  en hoger"
      }
    },
    "option_2": {
      "swatch_value": "#b6d7a8",
      "sort_order": 2,
      "admin_name": "20 & Above",
      "en": {
        "label": "20 & Above"
      },
      "fr": {
        "label": "20 et plus"
      },
      "nl": {
        "label": "20 en hoger"
      }
    }
  },
  "is_required": 0,
  "is_unique": 0,
  "validation": "numeric",
  "value_per_locale": 0,
  "value_per_channel": 0,
  "is_configurable": 0,
  "is_visible_on_front": 0,
  "use_in_flat": 0,
  "is_comparable": 0
}

Expected Result

The attribute should be created with the options saved and visible in the response and in the admin panel.

Actual Result

The attribute is created, but the options array is empty, and no options are saved.

Source Code Analysis

I checked the source code at vendor/bagisto/rest-api/src/Http/Controllers/V1/Admin/Catalog/AttributeController.php.
The store() method does not process or save the options field at all, unlike the web admin controller.

Environment

  • Bagisto version: 2.3.0
  • bagisto/rest-api verson: https://github.com/bagisto/rest-api/tree/ef41c3178d5dee5b634b7dfc60cf9831fa34b1ff
  • PHP version: 8.2.28

Additional Information

This is a critical feature for headless and automated integrations.
Please add support for saving attribute options via the REST API, just like the web admin panel.

Thank you!

DJB-Developer avatar Apr 30 '25 13:04 DJB-Developer