---
title: "companies"
description: "Company List Query"
doc_type: graphql
doc_category: adminGraphQL
doc_version: v20270301
source_url:
  html: 'https://developer.shopline.com/docs/admin-graph-ql-api/b-2-b/queries/companies'
  md: 'https://developer.shopline.com/docs/admin-graph-ql-api/b-2-b/queries/companies.md'
---
# companies

Company List Query

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

## Arguments

* `after`

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

  Returns elements following the specified cursor. The `first` argument must also be specified when using this argument.

* `before`

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

  Returns elements preceding the specified cursor. The `last` argument must also be specified when using this argument.

* `first`

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

  Returns the first n elements in the list. 

* `last`

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

  Returns the last n elements in the list. 

* `reverse`

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

  Whether to reverse the order of the list. 
  
  ● true: reverse
  
  ● false: do not reverse
  
  Default value: false

* `sortKey`

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

  sort key

* `rawQuery`

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

  Query criteria, JSON string.
  Currently, only company name and location name queries are supported, such as `{"queryParam": "Global Ball Company"}`

## Returns

* `edges`

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

  edge list

* `nodes`

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

  node list

* `pageInfo`

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

  pageInfo

## Examples

### Company list query

Paging to query company list information

**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": {
              "id": "gid://shopline/Company/6261711218190850599",
              "locationCount": 9,
              "mainContact": {
                "id": "gid://shopline/CompanyContact/4600512895"
              },
              "name": "Big bom",
              "orderCount": 0,
              "totalSpent": {
                "currencyCode": "USD",
                "amount": "0"
              },
              "contactCount": 5
            }
          }
        ],
        "nodes": [
          {
            "totalSpent": {
              "amount": "0",
              "currencyCode": "USD"
            },
            "contactCount": 5,
            "id": "gid://shopline/Company/6261711218190850599",
            "locationCount": 9,
            "mainContact": {
              "id": "gid://shopline/CompanyContact/4600512895"
            },
            "name": "Big bom",
            "orderCount": 0
          }
        ],
        "pageInfo": {
          "endCursor": "E002CE0E792FBA4E98672D39851FDFD6",
          "hasNextPage": false,
          "hasPreviousPage": false,
          "startCursor": "AF52536A1951B28A30AAE8825A2B69B9"
        }
      }
    }
  }
}
```

## Error Handling

For detailed information about common codes, see [Status and error codes](https://developer.shopline.com/docs/apps/api-instructions-for-use/graph-ql-admin-api/overview.md#status-and-error-codes).

