# Set a customer's company roles

URL: https://docs.sparklayer.io/developers/api/customers/set-a-customers-company-roles
Operation: `PUT /api/v2/customers/{lookupBy}/{identifier}/company-roles` (operationId `updateCustomerCompanyRoles`)
OpenAPI spec: https://docs.sparklayer.io/openapi/customers.yaml

Replaces the customer's role in a [company](https://docs.sparklayer.io/help/customers/companies.md), or their roles in its [locations](https://docs.sparklayer.io/help/customers/company-locations.md), and returns `204`.

- **Each key** is `co:<type>:<identifier>` for the company or `se:<type>:<identifier>` for a location (section), where `<type>` is `s` (SparkLayer ID), `p` (platform ID) or `x` (integration ID). All the keys are for one company.
- **Each value** is a role slug. A company key set to `null` gives the company for the location keys without giving a company-wide role.
- **An empty object** removes the customer from every company and location, except where they are an admin.
- **Sales roles** can't be assigned here: assign them in the Dashboard.

`PUT /api/v2/customers/{lookupBy}/{identifier}/company-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 -X PUT "https://app.sparklayer.io/api/v2/customers/platform/7843024560291/company-roles" \
  -H "Authorization: Bearer $SPARKLAYER_TOKEN" \
  -H "Site-Id: $SPARKLAYER_SITE_ID" \
  -H "Content-Type: application/json" \
  -d '{
  "co:s:9151f21f-43ae-43b4-92f3-f4af67cdf544": null,
  "se:p:dept-123": "limited-customer",
  "se:x:dept-integration-456": "main"
}'
```

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`.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `lookupBy` | "sparklayer" \| "platform" \| "email" | Yes | What `identifier` is: `sparklayer` (the customer's SparkLayer ID), `platform` (their ID on your eCommerce platform) or `email` (their email address). Example: `platform` |
| `identifier` | string | Yes | The customer's ID or email address, of the kind set by `lookupBy`. SparkLayer IDs are UUIDs; legacy `cu_` IDs work too, except for shopping lists and favourites. Email lookups are exact and case-sensitive: URL-encode the address, with `+` as `%2B`. Example: `7843024560291` |

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

### Request body (`application/json`) (required)

Replace the customer's company-level role assignment or section-level role assignments within one company. Keys must use co:<id_type>:<identifier> for the company target or se:<id_type>:<identifier> for section targets. id_type must be s (SparkLayer ID), p (platform/external_id), or x (integration_id). A company key with a string value assigns a company-level role. A company key with null provides the company context for section role keys. Send an empty object to detach the customer from all companies and sections.

Type: `object`

```json
{
  "co:s:9151f21f-43ae-43b4-92f3-f4af67cdf544": null,
  "se:p:dept-123": "limited-customer",
  "se:x:dept-integration-456": "main"
}
```

### Responses

#### 204: Empty Response

#### 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"
    }
  ]
}
```
