---
title: "companies"
description: "公司列表查询"
doc_type: graphql
doc_category: adminGraphQL
doc_version: v20270301
source_url:
  html: 'https://developer.shopline.com/zh-hans-cn/docs/admin-graph-ql-api/b-2-b/queries/companies'
  md: 'https://developer.shopline.com/zh-hans-cn/docs/admin-graph-ql-api/b-2-b/queries/companies.md'
---
# companies

公司列表查询

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

## Arguments

* `after`

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

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

* `before`

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

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

* `first`

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

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

* `last`

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

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

* `reverse`

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

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

* `sortKey`

  [CompanySortKeys](https://developer.shopline.com/zh-hans-cn/docs/admin-graph-ql-api/b-2-b/enums/company-sort-keys.md)

  排序规则

* `rawQuery`

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

  查询条件，json字符串。
  当前仅支持公司名称和地点名称查询，例如`{"queryParam": "Globale Ball Company"}`

## Returns

* `edges`

  [[CompanyEdge!]](https://developer.shopline.com/zh-hans-cn/docs/admin-graph-ql-api/b-2-b/objects/company-edge.md)

  edges列表

* `nodes`

  [[Company]](https://developer.shopline.com/zh-hans-cn/docs/admin-graph-ql-api/b-2-b/objects/company.md)

  节点列表

* `pageInfo`

  [PageInfo!](https://developer.shopline.com/zh-hans-cn/docs/admin-graph-ql-api/common-objects/objects/page-info.md)

  分页信息

## Examples

### 公司列表查询

分页查询公司列表信息

**Request:**

```json
query {
  companies(first: 2, rawQuery: "{\"queryParam\": \"Big bom\"}",after:null,before:null,reverse:true,sortKey: CREATED_AT) {
    edges {
      cursor
      node {
        id
        name
        orderCount
        contactCount
        locationCount
        totalSpent {
            amount
            currencyCode
        }
        mainContact{
                id
            }
        }
    }
    nodes {
        id
        name
        orderCount
        contactCount
        locationCount
        totalSpent {
            amount
            currencyCode
        }
        mainContact{
            id
        }
    }
    pageInfo {
        endCursor
        hasNextPage
        hasPreviousPage
        startCursor
    }
  }
}
```

**Response:**

```json
{
  "data": {
    "data": {
      "companies": {
        "edges": [
          {
            "cursor": "-",
            "node": {
              "contactCount": 5,
              "id": "gid://shopline/Company/6261711218190850599",
              "locationCount": 9,
              "mainContact": {
                "id": "gid://shopline/CompanyContact/4600512895"
              },
              "name": "Big bom",
              "orderCount": 0,
              "totalSpent": {
                "amount": "0",
                "currencyCode": "USD"
              }
            }
          }
        ],
        "nodes": [
          {
            "orderCount": 0,
            "totalSpent": {
              "amount": "0",
              "currencyCode": "USD"
            },
            "contactCount": 5,
            "id": "gid://shopline/Company/6261711218190850599",
            "locationCount": 9,
            "mainContact": {
              "id": "gid://shopline/CompanyContact/4600512895"
            },
            "name": "Big bom"
          }
        ],
        "pageInfo": {
          "endCursor": "E002CE0E792FBA4E98672D39851FDFD6",
          "hasNextPage": false,
          "hasPreviousPage": false,
          "startCursor": "AF52536A1951B28A30AAE8825A2B69B9"
        }
      }
    }
  }
}
```

## Error Handling

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

