# List customer roles

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

Returns all roles for the site (site-scoped plus default roles). Includes assigned_customer_count for the current site.

`GET /api/v2/customer-roles`

**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/customer-roles" \
  -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`.

### 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

An array. Each item:

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `[].id` | string (uuid) | Yes | |
| `[].name` | string | Yes | Length: max 50. |
| `[].slug` | string | Yes | Length: max 64. |
| `[].type` | "customer" \| "sales" | Yes | |
| `[].permissions` | object \| null | | Map of permission key (see PermissionKey enum) to boolean. Only keys from PermissionKey are accepted; invalid keys return 400. |
| `[].is_default` | boolean | | True when this role is a built-in default (cannot be updated or deleted). Derived from IsDefaultRoleID. |
| `[].assigned_customer_count` | integer | | Number of customers assigned this role for the current site. Min 0. |

```json
[
  {
    "id": "019bbd11-4e64-735f-9205-5b7bc84181f6",
    "name": "My Custom Role",
    "slug": "my-custom-role",
    "type": "customer",
    "permissions": {
      "purchase-edit-prices": true,
      "customers-create-new": false
    },
    "is_default": true,
    "assigned_customer_count": 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"
    }
  ]
}
```
