---
title: "collections"
description: "查询店铺分类列表。"
doc_type: graphql
doc_category: storefront
doc_version: v20270301
source_url:
  html: 'https://developer.shopline.com/zh-hans-cn/docs/storefront-api/products/queries/collections'
  md: 'https://developer.shopline.com/zh-hans-cn/docs/storefront-api/products/queries/collections.md'
---
# collections

查询店铺分类列表。

- **API Version:** v20270301
- **API Type:** Storefront
- **API Protocol:** GraphQL
- **Operation Type:** Query

## Arguments

* `after`

  [String](https://developer.shopline.com/zh-hans-cn/docs/storefront-api/common/scalars/string.md)

  返回指定游标之后的元素。如果指定了该参数，也必须要指定 `first` 参数。

* `before`

  [String](https://developer.shopline.com/zh-hans-cn/docs/storefront-api/common/scalars/string.md)

  返回指定游标之前的元素。如果指定了该参数，也必须要指定 `last` 参数。

* `first`

  [Int](https://developer.shopline.com/zh-hans-cn/docs/storefront-api/common/scalars/int.md)

  返回列表中的前 n 个元素。

* `last`

  [Int](https://developer.shopline.com/zh-hans-cn/docs/storefront-api/common/scalars/int.md)

  返回列表中的最后 n 个元素。

* `reverse`

  [Boolean](https://developer.shopline.com/zh-hans-cn/docs/storefront-api/common/scalars/boolean.md)

  是否反转列表的顺序。
  
  ● true：反转
  
  ● false：不反转
  
  默认值：false

* `sortkey`

  [CollectionSortKeys](https://developer.shopline.com/zh-hans-cn/docs/storefront-api/products/enums/collection-sort-keys.md)

  按特定维度对列表排序。

* `query`

  [String](https://developer.shopline.com/zh-hans-cn/docs/storefront-api/common/scalars/string.md)

  对查询应用一个或多个过滤器。
  
  :::warning{title="注意"}
  1.如果参数值包含关键字，必须先对关键字进行转义。
  
  2.查询最多支持 5 个过滤器。
  :::
  
  | 过滤器字段 | 描述 |
  | --- | --- |
  | collection_type | 按分类类型查询。有效枚举值包含 `manual`（手动分类）和 `smart`（智能分类）。若未指定分类类型，将返回所有类型的分类。 |
  | title | 按分类标题查询。目前仅支持搜索一个标题。 |
  | updated_at | 按分类更新时间查询。格式：[ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html)。支持时间范围搜索。|
  
  #### 语法参考
  
  ```js
  title:'T-shirt' AND updated_at:>'2020-10-21T23:39:20Z'
  ```
  

* `ids`

  [[ID]](https://developer.shopline.com/zh-hans-cn/docs/storefront-api/common/scalars/id.md)

  指定查询的分类 ID，多个 ID 用英文逗号分隔。

## Returns

* `edges`

  [[CollectionEdge!]](https://developer.shopline.com/zh-hans-cn/docs/storefront-api/products/objects/collection-edge.md)

  分类信息

* `nodes`

  [[Collection]](https://developer.shopline.com/zh-hans-cn/docs/storefront-api/products/objects/collection.md)

   CollectionEdge 中包含的节点列表

* `pageInfo`

  [PageInfo!](https://developer.shopline.com/zh-hans-cn/docs/storefront-api/online-store/objects/page-info.md)

  分页信息

* `totalCount`

  [Int](https://developer.shopline.com/zh-hans-cn/docs/storefront-api/common/scalars/int.md)

  分类发布在该渠道的数量

## Examples

### 根据指定标题查询分类

根据指定标题查询分类。

**Request:**

```json
query collections @inContext(saleChannel: "web",country:CN,language:EN){
  collections(first: 2, query: "title:\"collection\" OR title:\"Custom\"" ) {
    edges {
      node {
        id
        title
        products(first: 2) {
          edges {
            node {
              id
              title
            }
          }
        }
      }
    }
  }
}
```

**Response:**

```json
{
  "data": {
    "data": {
      "collections": {
        "edges": [
          {
            "node": {
              "id": "gid://shopline/Collection/12261186277836500577262340",
              "products": {
                "edges": []
              },
              "title": "Third Custom Collection"
            }
          },
          {
            "node": {
              "id": "gid://shopline/Collection/12273187462690727542132340",
              "products": {
                "edges": [
                  {
                    "node": {
                      "id": "gid://shopline/Product/16073187380346473690812340",
                      "title": "A product title"
                    }
                  }
                ]
              },
              "title": "Third Custom Collection"
            }
          }
        ]
      }
    },
    "extensions": {
      "cost": {
        "actualQueryCost": 31,
        "requestedQueryCost": 31,
        "throttleStatus": {
          "currentlyAvailable": 4969,
          "maximumAvailable": 5000,
          "restoreRate": 5000
        }
      }
    }
  }
}
```

## Error Handling

关于更多通用错误码说明，参考：[状态码和错误码](https://developer.shopline.com/zh-hans-cn/docs/apps/api-instructions-for-use/storefront-api/overview.md#status-and-error-codes)。

