# Attribute vocabulary

Maintain product-code and family attributes, values, display order, and family assignments.

Canonical HTML: https://developer.shelfcycle.com/guides/attribute-vocabulary

Maintain product-code and product-family attribute definitions, accepted values, display order, and typed family assignments.

## Choose the vocabulary

Use `/product-code-attributes` for attributes assigned to individual products, and `/catalog-attributes` for attributes assigned to product families. The two vocabularies have the same management routes:

| Action | Route relative to either vocabulary |
| --- | --- |
| List or create definitions | GET or POST the vocabulary root |
| Read, rename, or delete a definition | GET, PATCH, or DELETE `/{attributeId}` |
| Arrange definitions | POST `/reorder` |
| List or create values | GET or POST `/{attributeId}/values` |
| Read or delete a value | GET or DELETE `/{attributeId}/values/{valueId}` |
| Arrange values | POST `/{attributeId}/values/reorder` |

Vocabulary reads accept `product-attributes:read`, `product-attributes:write`, `products:read`, `products:write`, or `search:read`, together with current Product reference access (view, view all, create, or update). Vocabulary writes require `product-attributes:write` and current Product update permission. Full-access keys include the new scopes; restricted keys need explicit grants for vocabulary writes.

Names and value labels may repeat. Keep the returned UUIDs, not names, as identities. Definition types are `SELECT`, `MULTISELECT`, `FREE_TEXT`, and `BOOLEAN`.

## Discover and create

```bash
curl "$SHELFCYCLE_API_BASE_URL/catalog-attributes?limit=50&type=SELECT" \
  -H "Authorization: Bearer $SHELFCYCLE_API_KEY"

curl "$SHELFCYCLE_API_BASE_URL/catalog-attributes?dryRun=true" \
  -X POST \
  -H "Authorization: Bearer $SHELFCYCLE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: catalog:market-definition-001" \
  -d '{"name":"Market","type":"SELECT"}'
```

After a ready preview, submit the same body and key without `dryRun=true`. Creation returns `201` and `idempotencyStatus: "created"`; an identical retry returns `200 replayed`. Use the returned attribute ID to create a selected value:

```bash
curl "$SHELFCYCLE_API_BASE_URL/catalog-attributes/$ATTRIBUTE_ID/values?dryRun=true" \
  -X POST \
  -H "Authorization: Bearer $SHELFCYCLE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: catalog:market-industrial-001" \
  -d '{"value":"Industrial"}'
```

Lists paginate by ID, not display order. `seq` is each row's display position. Keep the original filters and page size when continuing with `meta.nextCursor`; do not confuse page order with display order. Definitions can be filtered by `id`, `name`, or `type`, and values by `id` or `value`.

## Rename, arrange, or remove

Read the exact definition or value before a change. PATCH a definition with only `{"name":"New name"}` and its current `updatedAt` in `If-Match`. The definition's type remains unchanged; values are created or removed rather than renamed.

Reorder with `{"orderedIds":["first-uuid","second-uuid"]}` on the matching `/reorder` route. Include every current member of that collection exactly once. Reordering needs neither `Idempotency-Key` nor `If-Match`; a repeated current order returns `changed: false`. If membership has changed, `stale_record` asks you to read the complete collection again before submitting a fresh order.

DELETE a definition or value with its own current `updatedAt` as `If-Match`. An in-use definition returns `422 attribute_in_use`, and an in-use value returns `422 attribute_value_in_use`; inspect the returned blockers before choosing another action. Missing or outdated timestamps return `409 stale_record`. Every management write accepts `dryRun=true`, including reordering and deletion. A create preview without a key, or a change preview without the required timestamp, reports blocked readiness.

## Apply family assignments

Vocabulary management and assignment are separate. Use `products:write` with current Product create permission for a new family, or Product update permission for family PATCH. New families use `Idempotency-Key`; PATCH uses the family's current `updatedAt` as `If-Match`.

Add `catalogAttributeAssignments` to the family request, using exact catalog attribute and option IDs. Replace these example UUIDs with the IDs you resolved:

```json
{
  "catalogAttributeAssignments": [
    {"attributeId":"11111111-1111-4111-8111-111111111111","optionIds":["22222222-2222-4222-8222-222222222222"]},
    {"attributeId":"33333333-3333-4333-8333-333333333333","textValue":"Clear"},
    {"attributeId":"44444444-4444-4444-8444-444444444444","booleanValue":false}
  ]
}
```

Match each value to its definition type. A `BOOLEAN` assignment must explicitly send `true` or `false`; an unknown or mismatched assignment returns `422 attribute_assignments_invalid`.

On PATCH, the supplied array replaces the complete assignment set. Leave an attribute out of that array to remove it, send `[]` to clear all assignments, or omit `catalogAttributeAssignments` to preserve them. The response repeats the accepted assignment set only when the request included the field.

Use `GET /product-families/{id}/attribute-assignments` with `products:read` and current Product viewing access for paginated readback. `meta.ownerUpdatedAt` identifies the family version. Individual products continue to use `attributeAssignments` and the product-code vocabulary, as described in [Product setup](/guides/product-setup).

`GET /me` reports vocabulary actions under `effectiveCapabilities.products.codeAttributes` and `productFamilies.attributes`, plus family `attributeAssignments` view/update availability.
