Skip to content

Catalog Attribute — Create

Creates a new product attribute. Mirrors Catalog → Attributes → Create in the Bagisto admin panel. The same event hooks fire (catalog.attribute.create.before / catalog.attribute.create.after), so any core listener (search reindex, cache flush, etc.) is triggered.

Endpoint

EndpointMethod
/api/admin/catalog/attributesPOST

Request body

FieldTypeRequiredNotes
codestringyesSnake_case identifier. Must be unique and not a reserved word.
admin_namestringyesInternal admin label.
typestringyesOne of text, textarea, price, boolean, select, multiselect, checkbox, date, datetime, image, file.
swatch_typestring|nullnocolor, image, or text. Only relevant for select/multiselect.
is_required / is_unique / is_filterable / is_configurable / is_visible_on_front / is_comparable / value_per_locale / value_per_channel / enable_wysiwygbooleannoStandard attribute flags.
validationstring|nullnoValidation rule — numeric, email, decimal, url or regex.
regexstring|nullwith regexThe pattern values must match, e.g. /^[A-Z]{2}-\d{4}$/.
default_valuestring|nullnoDefault value for the attribute.
positionintegernoDisplay order.
translationsobjectnoMap of locale → { name }.
optionsarraynoInitial options (select/multiselect/checkbox only). Each entry: { admin_name, sort_order?, swatch_value?, translations? }.

Validation and the regex pattern

validation names the rule a value must satisfy — numeric, email, decimal, url or regex. Choosing regex makes regex required, and the pattern is checked before it is stored.

A pattern must be delimited with /, may carry only the i, m, s and u modifiers, and must compile. That is narrower than PHP alone accepts because the same pattern is also written into the storefront's own form rules, where a # delimiter or a PCRE-only modifier would break the form for every product using the attribute. A pattern that does not qualify is refused rather than stored.

Response

201 Created returning the full attribute detail — identical shape to GET /api/admin/catalog/attributes/{id}.

Errors

HTTPCause
401 UnauthorizedMissing or invalid Bearer token
422 Unprocessable EntityValidation failure (missing/duplicate code, invalid type, malformed body)

Notes

  • The code field is immutable after creation — see the Update endpoint.
  • The repository returns a contract interface — the response is re-fetched as a full Eloquent model so the payload always carries translations and options.
  • For attribute types that do not support options (text, textarea, boolean, etc.), the options array in the response is null.

Released under the MIT License.