# The category model

Source: https://developers.swell.is/backend-api/categories/the-category-model

## Fields

- `id` (objectId): Unique identifier for the category.
- `name` (string, required): A human-friendly name for the category.
- `active` (boolean): Indicates the category may be visible to customers. Otherwise it will be hidden from view. Default: `false`.
- `children` (Category): Expandable list of child categories.
- `date_created` (date, auto): Date and time the category was created.
- `date_updated` (date, auto): Date and time the category was last updated.
- `demo` (boolean): Indicates the category is a demo.
- `description` (string): A long-form description of the category. Can contain HTML or other markup languages.
- `image` (object): Image depicting the category.

  Deprecated — use `images` instead.
  - `caption` (string)
  - `file` (object): An object representing the image's source file.
    - `id` (objectId): Unique identifier for the file.
    - `filename` (string): Optional file name.
    - `data` (filedata): A reference to the raw file data.
    - `content_type` (string): MIME content type of the file.
    - `date_uploaded` (date): Date the file was uploaded.
    - `height` (int): Image height in pixels, if applicable.
    - `length` (int): Size of the file in bytes.
    - `metadata` (object): A set of arbitrary data that is typically used to store custom values.
    - `md5` (string): An MD5 hash of the file contents. This can be used to uniquely identify the file for caching purposes.
    - `private` (boolean): Indicates whether the file is private.
    - `url` (string): A public URL to reference the file. Updated automatically if file content changes.
    - `width` (int): Image width in pixels, if applicable.
- `images` (array of object): List of images depicting the category.
  - `id` (objectId, auto): Unique identifier for the object.
  - `caption` (string): A brief description of the image.
  - `file` (object): An object representing the image file.
    - `id` (objectId): Unique identifier for the file.
    - `content_type` (string): MIME content type of the file.
    - `data` (filedata): A reference to the raw file data.
    - `date_uploaded` (date): Date the file was uploaded.
    - `filename` (string): Optional file name.
    - `height` (int): Image height in pixels, if applicable.
    - `length` (int): Size of the file in bytes.
    - `md5` (string): An MD5 hash of the file contents. This can be used to uniquely identify the file for caching purposes.
    - `url` (string): A public URL to reference the file. Updated automatically if file content changes.
    - `width` (int): Image width in pixels, if applicable.
    - `metadata` (object): Arbitrary image data, typically used to store custom values. See Frontend API for more details.
    - `private` (boolean): Indicates the image is not visible to customers.
- `meta_description` (string): Page description used for search engine optimization purposes.
- `meta_keywords` (string): Page keywords used for search engine optimization purposes.
- `meta_title` (string): Page title used to override product name in storefronts.
- `parent_id` (objectId): ID of the parent category, if applicable.
- `parent` (Category): Expandable link to the parent category, if applicable.
- `products` (array of Products): Expandable list of category products.
- `products_indexed` (Product): Expandable list of products as indexed and sorted by their respective position.
- `slug` (string, required): Unique identifier typically used in URLs. Defaults to `name` converted to lowercase and hyphenated. If the category has a parent, the default slug will be prefixed with the parent slug. Maximum length of 1,000 characters. Default: `{"$formula":"slug(if(parent_id, join('-', parent.name, name), name))"}`.
- `sort` (int): Position of the category in a list.
- `sorting` (string): Default product sorting applied when retrieving products using the `category` or `categories` filter. Can be one of `popularity`, `price_asc`, `price_desc`, `date_asc`. `date_desc`. If not specified, products are sorted by their manually defined `sort` value.
- `theme_template` (string): ID of an alternate theme template used to render this category in a storefront, if applicable.
- `attributes` (object): An object containing custom attribute key/value pairs.
- `attributes_template` (array of object): Template of attribute id/value pairs to apply to products added to this category.
- `top` (Category): Expandable link to the top level category.
- `top_id` (objectId): ID of the top level category in the hierarchy.

## Example response

```json
{
  "name": "Luck",
  "active": true,
  "sorting": null,
  "images": [
    {
      "file": {
        "id": "628bb4ba499bba0019b1ab7c",
        "date_uploaded": "2022-05-23T16:22:18.978Z",
        "length": 52772,
        "md5": "82fd851c2edcd4bd7ed941c561e605ea",
        "filename": null,
        "content_type": "image/gif",
        "metadata": null,
        "url": "https://cdn.schema.io/launch-storefront/628bb4ba499bba0019b1ab7c/82fd851c2edcd4bd7ed941c561e605ea",
        "width": 127,
        "height": 127
      },
      "id": "628bb4be499bba0019b1ab7e"
    }
  ],
  "description": "Luck affects all skills a little bit&mdash;with the exception of Acrobatics and Athletics.<br>",
  "meta_title": "Luck",
  "meta_description": "Luck affects all skills a little bit—not including Acrobatics and Athletics.",
  "parent_id": "628bae71499bba0019b1aac2",
  "slug": "skills-luck",
  "top_id": "628bae71499bba0019b1aac2",
  "date_created": "2022-05-23T16:06:40.137Z",
  "date_updated": "2022-05-23T16:22:22.300Z",
  "sort": 7,
  "id": "628bb1101869c10019b4205c"
```
