Skip to content

Get Attribute

About

The attribute query returns one product attribute with its configuration, its selectable options, and its per-locale names. Use it to:

  • Read one attribute's option list to render a colour, size, or brand control
  • Check how an attribute behaves before using it — whether it is filterable, whether it drives configurable variants, whether its value varies per locale or channel
  • Read the swatch data behind a colour or image picker
  • Fetch an attribute's label in every locale a store supports

Use Attributes to list them, or Category Attribute Filters to get only the attributes that belong on a given category's filter sidebar.

Arguments

ArgumentTypeRequiredDescription
idID!✅ YesIdentifies the attribute. Accepts the IRI form (/api/shop/attributes/23) or a plain numeric ID ("23").

An ID that is neither form is rejected as an invalid format, and an ID that resolves to no attribute returns data.attribute as null with an entry in errors.

Possible Returns

The is* and valuePer* flags come back as the strings "1" / "0", not as GraphQL booleans.

FieldTypeDescription
idID!IRI-style identifier (/api/shop/attributes/23).
_idInt!Numeric attribute ID.
codeString!Machine-readable code — color, size, brand, sku. This is the key you pass to a product filter.
adminNameString!Admin-facing name. Use translation for the shopper-facing label.
typeString!Input type — text, textarea, select, multiselect, boolean, date, datetime, price, image, file, checkbox. Decides which control to render.
swatchTypeStringcolor, image, text, or null. When color, render each option's swatchValue; when image, render swatchValueUrl.
positionIntSort order among attributes.
isRequiredString!"1" when the attribute is mandatory on the product form.
isUniqueString!"1" when values must be unique across products.
isFilterableString!"1" when the attribute can drive layered navigation.
isComparableString!"1" when the attribute appears on the compare page.
isConfigurableString!"1" when the attribute can define configurable-product variants.
isUserDefinedString!"1" for a merchant-created attribute, "0" for a system one.
isVisibleOnFrontString!"1" when the attribute is shown on the product page.
valuePerLocaleString!"1" when the value differs per locale.
valuePerChannelString!"1" when the value differs per channel.
defaultValueIntDefault option ID, when the attribute defines one.
validationStringValidation rule applied to the value, e.g. decimal, numeric, email.
validationsStringAdditional validation metadata.
regexStringRegular expression the value must match, when configured.
columnNameStringUnderlying storage column, when applicable.
enableWysiwygString!"1" when the admin editor uses a rich-text field.
createdAtStringISO 8601 creation timestamp.
updatedAtStringISO 8601 timestamp of the last change.
optionsAttributeOptionCursorConnectionSelectable values. Empty for free-text and price attributes.
translationAttributeTranslationThe attribute's name in the current locale.
translationsAttributeTranslationCursorConnectionThe attribute's name in every locale.

Option Fields

Each node in the options connection:

FieldTypeDescription
idID!IRI-style option identifier.
_idInt!Numeric option ID. This is the value to send when filtering products.
adminNameStringAdmin-facing option name. Use translation for the shopper-facing label.
sortOrderIntDisplay order within the attribute.
swatchValueStringHex colour for a colour swatch, or the text value.
swatchValueUrlStringURL of the swatch image, for image swatches.
translationAttributeOptionTranslationThe option's label in the current locale.
translationsAttributeOptionTranslationCursorConnectionThe option's label in every locale.

Translation Fields

FieldTypeDescription
idID!IRI-style translation identifier.
_idInt!Numeric translation ID.
localeString!Locale code this translation belongs to.
attributeIdString!Parent attribute ID, on an attribute translation.
attributeOptionIdString!Parent option ID, on an option translation.
nameStringAttribute name in that locale.
labelStringOption label in that locale.

Use Cases

1. Rendering a colour swatch picker

Read swatchType to decide how to draw each option, then read the options themselves.

graphql
query colourPicker {
  attribute(id: "/api/shop/attributes/23") {
    code
    swatchType
    options(first: 50) {
      edges {
        node {
          _id
          adminName
          swatchValue
          swatchValueUrl
          translation {
            label
          }
        }
      }
      totalCount
    }
  }
}

Render swatchValue as a colour chip when swatchType is color, and swatchValueUrl as an image when it is image. Show translation.label rather than adminName, which is an internal name.

2. Turning a selection into a product filter

An option's _id is the value the product listing expects, keyed by the attribute's code:

json
{
  "filter": "{"color": "3"}"
}

Pass that to List Products. Comma-separate several option IDs to match any of them.

3. Building a language switcher for attribute labels

Read translations on the attribute and on each option to cache every locale in one request, instead of re-querying per language.

Best Practices

  1. Filter by code, select by _id — the product filter key is the attribute's code and the value is the option's _id; neither the IRI nor adminName works there
  2. Display translation.label, never adminNameadminName is the internal admin label and is not translated
  3. Compare the flags against stringsisFilterable and its siblings return "1" / "0", so a truthiness test on the string "0" reports the wrong answer in most languages
  4. Read swatchType before rendering options — it decides whether an option carries a colour, an image URL, or neither
  5. Page the options connection on large attributes — a brand list runs to hundreds of options, and the connection defaults to 10 per page
  6. Prefer Category Attribute Filters for a filter sidebar — it returns only the attributes marked filterable for that category, already scoped

Error Scenarios

ScenarioCause
Attribute not foundThe ID resolves to no attribute. data.attribute is null with an entry in errors.
Invalid ID formatThe ID is neither an IRI nor numeric.
Missing IDThe id argument was omitted. GraphQL rejects the document before the query runs.

Released under the MIT License.