# Categories 

Source: https://developers.swell.is/frontend-api/categories

**Swell.js:**

Retrieve product categories to display in a storefront.

### List categories

*Returns a list of product categories, with offset pagination using* *`limit`* *and* *`page`**.*

**List categories**

**swell.js**

```javascript
await swell.categories.list({
  limit: 25,
  page: 1
})
```

### Get a category

*Returns a single category.*

**Get a category**

**swell.js** `By slug`

```javascript
await swell.categories.get('mens-shirts')
```

**swell.js** `By ID`

```javascript
await swell.categories.get('5c15505200c7d14d851e510g')
```

**GraphQL:**

Retrieve product categories to display in a storefront.

### List categories

Returns a list of product categories, with offset pagination using `limit` and `page`. Use this query to optimize your store by pre-generating data for each category page ahead of time.

The parameters for this query are `search`, `where`, `sort`, `limit`, `page`, `_locale`, and `_currency`.

**List categories**

**GraphQL**

```graphql
# Returns 10 categories per page, starting on page 2.
query getCategories {
  categories(limit: 10, page: 2) {
    results {
      name
      slug
    }
  }
}
```

### Get a category

Returns a single category by slug or ID, including its products and images. Use this query to pre-load category data for your storefront pages.

**Parameters**

- For querying `categoryBySlug`: `slug` (required), `_locale`, and `_currency`
- For querying `categoryById`: `id` (required), `_locale`, and `_currency`

**Get a category**

**GraphQL** `By slug`

```graphql
# Returns categories and their images by slug.
query getCategoryPreviewData {
  categoryBySlug(slug: "mens-shirt", _locale: "en-US") {
    name
    slug
    products {
      id
      name
      slug
      price
      currency
    }
    images {
      caption
      file {
        url
        width
        height
      }
    }
  }
}
```

**GraphQL** `By id`

```graphql
# Returns categories and their images by ID.
query getCategoryPreviewData {
  categoryById(id: "5c15505200c7d14d851e510g", _currency: "USD") {
    name
    slug
    products {
      id
      name
      slug
      price
      currency
    }
    images {
      caption
      file {
        url
        width
        height
      }
    }
  }
}
```
