# List companies

URL: https://docs.sparklayer.io/developers/api/customers/list-companies
Operation: `GET /api/v2/companies` (operationId `getAllCompanies`)
OpenAPI spec: https://docs.sparklayer.io/openapi/customers.yaml

`GET /api/v2/companies`

**Base URLs:** `https://app.sparklayer.io` (Live), `https://test.app.sparklayer.io` (Test)

**Authentication:** send `Authorization: Bearer <access_token>` and `Site-Id: <site id>` with every request. Get the token from [Get an access token](https://docs.sparklayer.io/developers/api/core/get-an-access-token.md); see [Authentication](https://docs.sparklayer.io/developers/authentication.md).

### Example request

```bash
curl "https://app.sparklayer.io/api/v2/companies" \
  -H "Authorization: Bearer $SPARKLAYER_TOKEN" \
  -H "Site-Id: $SPARKLAYER_SITE_ID"
```

Set `SPARKLAYER_TOKEN` to an access token and `SPARKLAYER_SITE_ID` to your Site ID. For the test environment, use `https://test.app.sparklayer.io`.

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `page` | integer | | The page of results to fetch. Default: `1`. Min 1. |
| `page_size` | integer | | Number of records per page. Default: `50`. Min 1, max 100. |
| `search_term` | string | | Term to filter results by. Performs a wildcard, case-insensitive search on company name. Length: min 2. |
| `sales_agent_group` | string | | Only the companies with this sales agent group on any of their sections. Length: min 1. |
| `ids` | (string (uuid))[] | | Only the companies with these SparkLayer ids, up to 100, e.g. `?ids=<id>&ids=<id>` Items: max 100. |

### Header parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Site-Id` | string | Yes | Your SparkLayer Site ID, from Settings > API in the SparkLayer Dashboard. Length: min 1. Example: `jones-climbing` |

### Responses

#### 200: Success

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `data` | object[] | | |
| `data[].id` | string (uuid) | | SparkLayer ID |
| `data[].external_id` | string \| null | | The identifier on the e-commerce platform. Length: min 1, max 124. |
| `data[].integration_id` | string \| null | | The identifier used in another integration. Length: min 1, max 124. |
| `data[].name` | string | | Company name. Length: max 128. |
| `data[].customer_group` | string \| null | | Customer Group Slug. Length: min 1, max 128. |
| `data[].accounting_id` | string \| null | | |
| `data[].price_lists` | string[] \| null | | Section specific price lists (overrides customer group settings) |
| `data[].payment_on_account` | object \| null | | Allow payments on account when the order total meets available credit (overrides customer group settings). Default: `null`. |
| `data[].payment_on_account.credit_limit` | number (float) \| null | | Max 999999999.999. |
| `data[].payment_on_account.balance` | number (float) \| null | | What the customer owes. Sending it adds an entry to the customer's account credit ledger: an opening balance with `balance_date`, otherwise the balance as of now. Max 999999999.999. |
| `data[].payment_on_account.currency_code` | string \| null | | If set allows overriding the currency for the customer, otherwise the base currency of the store is to be used. Pattern: `^[A-Za-z]{3}$`. |
| `data[].payment_on_account.net_terms` | "7_days" \| "15_days" \| "30_days" \| "45_days" \| "60_days" \| "90_days" \| null | | |
| `data[].payment_on_account.balance_date` | string (date-time) \| null | | Makes `balance` an opening balance on this date: from then on, only orders and payments dated on or after it count towards the balance. Leave it out to set the balance as of now. |
| `data[].default_shipping_address_id` | string (uuid) \| null | | |
| `data[].default_billing_address_id` | string (uuid) \| null | | |
| `data[].allow_personal_addresses` | boolean \| null | | |
| `data[].allow_one_time_addresses` | boolean \| null | | |
| `data[].sales_agent_groups` | string[] \| null | | |
| `data[].platform_managed_fields` | ("customer_group" \| "price_lists" \| "payment_on_account" \| "sales_agent_groups" \| "allow_personal_addresses" \| "allow_one_time_addresses" \| "accounting_id")[] \| null | | The fields a platform sync sets here, which are edited on the platform rather than in SparkLayer. Omitted or null on a write leaves them as they are; an empty list means the platform sets none. |
| `data[].primary_customer` | object | | Simple representation of a customer |
| `data[].primary_customer.id` | string (uuid) | | SparkLayer Customer ID |
| `data[].primary_customer.first_name` | string | | First Name. Length: max 128. |
| `data[].primary_customer.last_name` | string | | Last Name. Length: max 128. |
| `data[].primary_customer.email` | string | | Email Address. Length: max 255. |
| `data[].primary_customer.status` | "active" \| "inactive" \| "archived" | | Status - login is allowed only via the `active` status. `archived` marks a former B2B customer (e.g. Shopify b2b tag removed); archived customers are preserved but hidden from listings and their email may be reused. Default: `active`. |
| `data[].current_balance` | number (float) | | Max 999999999.999. |
| `pagination` | object | | |
| `pagination.total` | integer | | The total number of available records |
| `pagination.per_page` | integer | | The number of records returned per page |
| `pagination.current_page` | integer | | The current page of results returned |
| `pagination.total_pages` | integer | | the total number of available pages |

```json
{
  "data": [
    {
      "id": "9151f21f-43ae-43b4-92f3-f4af67cdf544",
      "external_id": "123456789",
      "integration_id": "123456789",
      "name": "Acme Corp",
      "customer_group": "base",
      "accounting_id": "<accounting_id>",
      "price_lists": [
        "b2b_gb_gbp_123"
      ],
      "payment_on_account": null,
      "default_shipping_address_id": "3f2b8c1e-5d4a-4e6f-9b7c-1a2d3e4f5a6b",
      "default_billing_address_id": "3f2b8c1e-5d4a-4e6f-9b7c-1a2d3e4f5a6b",
      "allow_personal_addresses": true,
      "allow_one_time_addresses": true,
      "sales_agent_groups": [
        "south-west-uk"
      ],
      "platform_managed_fields": [
        "customer_group"
      ],
      "primary_customer": {
        "id": "9151f21f-43ae-43b4-92f3-f4af67cdf544",
        "first_name": "Tom",
        "last_name": "Jones",
        "email": "Tom.jones@climbing.com",
        "status": "active"
      },
      "current_balance": 0
    }
  ],
  "pagination": {
    "total": 0,
    "per_page": 0,
    "current_page": 0,
    "total_pages": 0
  }
}
```

#### Other statuses: An error. The body describes the problem: see [Errors](https://docs.sparklayer.io/developers/errors.md).

`application/problem+json`: the standard error body (below).

### Error body

Error responses with a body use this RFC 7807 problem details object. See [Errors](https://docs.sparklayer.io/developers/errors.md) for every status code and which errors to retry.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `detail` | string | | Human-readable summary of the error |
| `status` | integer | | HTTP Status code returned from API |
| `title` | string | | Machine-readable error code |
| `type` | string | | |
| `errors` | object[] | | |
| `errors[].code` | string | | A machine-readable error message |
| `errors[].property` | string | | The offending property, with the full path |
| `errors[].field` | string | | The offending property, stripped of the path |
| `errors[].message` | string | | A human-readable summary of the error |

```json
{
  "detail": "Data Validation Failed",
  "status": 400,
  "title": "invalid-api-request-contents",
  "type": "https://hub.sparklayer.io/tech-docs",
  "errors": [
    {
      "code": "unique-constraint-violation",
      "property": "purchase_identifiers.sparklayer",
      "field": "sparklayer",
      "message": "Each stock level must have a unique stock location and sku combination"
    }
  ]
}
```
