# Update a section

URL: https://docs.sparklayer.io/developers/api/customers/update-a-section
Operation: `PUT /api/v2/companies/{lookupBy}/{identifier}/sections/{sectionLookupBy}/{sectionIdentifier}` (operationId `updateSection`)
OpenAPI spec: https://docs.sparklayer.io/openapi/customers.yaml

`PUT /api/v2/companies/{lookupBy}/{identifier}/sections/{sectionLookupBy}/{sectionIdentifier}`

**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/companies/platform/7843024560291/sections/sparklayer/SECTIONIDENTIFIER" \
  -H "Authorization: Bearer $SPARKLAYER_TOKEN" \
  -H "Site-Id: $SPARKLAYER_SITE_ID" \
  -H "Content-Type: application/json" \
  -d '{
  "id": "9151f21f-43ae-43b4-92f3-f4af67cdf544",
  "external_id": "123456789",
  "integration_id": "123456789",
  "name": "Antimemetics Division",
  "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"
  ],
  "company_users": [
    {
      "customer_id": "9151f21f-43ae-43b4-92f3-f4af67cdf544",
      "role_id": "9151f21f-43ae-43b4-92f3-f4af67cdf544"
    }
  ],
  "parent_id": "9151f21f-43ae-43b4-92f3-f4af67cdf544",
  "sibling_id": "9151f21f-43ae-43b4-92f3-f4af67cdf544",
  "admin_ids": [
    "9151f21f-43ae-43b4-92f3-f4af67cdf544"
  ]
}'
```

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" \| "integration" | 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` |
| `sectionLookupBy` | "sparklayer" \| "platform" \| "integration" | Yes | Property to use for section look up. Example: `sparklayer` |
| `sectionIdentifier` | string | Yes | Identifier for the specific lookup chosen |

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

ContextProperties plus the sales agent groups a company or section assigns, and the fields a platform sync manages on it.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string (uuid) | | SparkLayer ID |
| `external_id` | string \| null | | The identifier on the e-commerce platform. Length: min 1, max 124. |
| `integration_id` | string \| null | | The identifier used in another integration. Length: min 1, max 124. |
| `name` | string | | Section name. Length: max 128. |
| `customer_group` | string \| null | | Customer Group Slug. Length: min 1, max 128. |
| `accounting_id` | string \| null | | |
| `price_lists` | string[] \| null | | Section specific price lists (overrides customer group settings) |
| `payment_on_account` | object \| null | | Allow payments on account when the order total meets available credit (overrides customer group settings). Default: `null`. |
| `payment_on_account.credit_limit` | number (float) \| null | | Max 999999999.999. |
| `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. |
| `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}$`. |
| `payment_on_account.net_terms` | "7_days" \| "15_days" \| "30_days" \| "45_days" \| "60_days" \| "90_days" \| null | | |
| `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. |
| `default_shipping_address_id` | string (uuid) \| null | | |
| `default_billing_address_id` | string (uuid) \| null | | |
| `allow_personal_addresses` | boolean \| null | | |
| `allow_one_time_addresses` | boolean \| null | | |
| `sales_agent_groups` | string[] \| null | | |
| `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. |
| `company_users` | object[] | | |
| `company_users[].customer_id` | string (uuid) | | |
| `company_users[].role_id` | string (uuid) | | |
| `parent_id` | string (uuid) \| null | | This section will me moved to be a child of the section with this ID |
| `sibling_id` | string (uuid) \| null | | This section will me moved to be before the section with this ID |
| `admin_ids` | (string (uuid))[] | | Customers who administer this section and every section below it. Unlike company_users, allowed on sections with children. Replaces the section's admins; omit to leave them unchanged. A customer can't be in both admin_ids and company_users. An admin's other assignments in this section and below are removed, and a customer who already administers a section above can't be added (customerIsAncestorAdmin). |

```json
{
  "id": "9151f21f-43ae-43b4-92f3-f4af67cdf544",
  "external_id": "123456789",
  "integration_id": "123456789",
  "name": "Antimemetics Division",
  "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"
  ],
  "company_users": [
    {
      "customer_id": "9151f21f-43ae-43b4-92f3-f4af67cdf544",
      "role_id": "9151f21f-43ae-43b4-92f3-f4af67cdf544"
    }
  ],
  "parent_id": "9151f21f-43ae-43b4-92f3-f4af67cdf544",
  "sibling_id": "9151f21f-43ae-43b4-92f3-f4af67cdf544",
  "admin_ids": [
    "9151f21f-43ae-43b4-92f3-f4af67cdf544"
  ]
}
```

### Responses

#### 200: Successful response, Section updated

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string (uuid) | | SparkLayer ID |
| `external_id` | string \| null | | The identifier on the e-commerce platform. Length: min 1, max 124. |
| `integration_id` | string \| null | | The identifier used in another integration. Length: min 1, max 124. |
| `name` | string | | Section name. Length: max 128. |
| `customer_group` | string \| null | | Customer Group Slug. Length: min 1, max 128. |
| `accounting_id` | string \| null | | |
| `price_lists` | string[] \| null | | Section specific price lists (overrides customer group settings) |
| `payment_on_account` | object \| null | | Allow payments on account when the order total meets available credit (overrides customer group settings). Default: `null`. |
| `payment_on_account.credit_limit` | number (float) \| null | | Max 999999999.999. |
| `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. |
| `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}$`. |
| `payment_on_account.net_terms` | "7_days" \| "15_days" \| "30_days" \| "45_days" \| "60_days" \| "90_days" \| null | | |
| `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. |
| `default_shipping_address_id` | string (uuid) \| null | | |
| `default_billing_address_id` | string (uuid) \| null | | |
| `allow_personal_addresses` | boolean \| null | | |
| `allow_one_time_addresses` | boolean \| null | | |
| `sales_agent_groups` | string[] \| null | | |
| `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. |
| `status` | "active" \| "archived" | | Status - `archived` marks a section (or company, via its root section) removed via deleteSection/deleteCompany; archived sections are preserved with their balance/order history but hidden from listings and lookups, and their name may be reused. Default: `active`. |
| `parent_id` | string (uuid) \| null | | |
| `company_users` | object[] | | |
| `company_users[].customer` | object | | Simple representation of a customer |
| `company_users[].customer.id` | string (uuid) | | SparkLayer Customer ID |
| `company_users[].customer.first_name` | string | | First Name. Length: max 128. |
| `company_users[].customer.last_name` | string | | Last Name. Length: max 128. |
| `company_users[].customer.email` | string | | Email Address. Length: max 255. |
| `company_users[].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`. |
| `company_users[].role` | object | | A role with id, name, slug, type and permissions (used in responses) |
| `company_users[].role.id` | string (uuid) | Yes | |
| `company_users[].role.name` | string | Yes | Length: max 50. |
| `company_users[].role.slug` | string | Yes | Length: max 64. |
| `company_users[].role.type` | "customer" \| "sales" | Yes | |
| `company_users[].role.permissions` | object \| null | | Map of permission key (see PermissionKey enum) to boolean. Only keys from PermissionKey are accepted; invalid keys return 400. |
| `company_users[].role.is_default` | boolean | | True when this role is a built-in default (cannot be updated or deleted). Derived from IsDefaultRoleID. |
| `admins` | object[] | | Customers who administer this section and every section below it. |
| `admins[].id` | string (uuid) | | SparkLayer Customer ID |
| `admins[].first_name` | string | | First Name. Length: max 128. |
| `admins[].last_name` | string | | Last Name. Length: max 128. |
| `admins[].email` | string | | Email Address. Length: max 255. |
| `admins[].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`. |
| `children` | SectionResponse[] | | |
| `current_balance` | number (float) | | Max 999999999.999. |

```json
{
  "id": "9151f21f-43ae-43b4-92f3-f4af67cdf544",
  "external_id": "123456789",
  "integration_id": "123456789",
  "name": "Antimemetics Division",
  "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"
  ],
  "status": "active",
  "parent_id": "3f2b8c1e-5d4a-4e6f-9b7c-1a2d3e4f5a6b",
  "company_users": [
    {
      "customer": {
        "id": "9151f21f-43ae-43b4-92f3-f4af67cdf544",
        "first_name": "Tom",
        "last_name": "Jones",
        "email": "Tom.jones@climbing.com",
        "status": "active"
      },
      "role": {
        "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
      }
    }
  ],
  "admins": [
    {
      "id": "9151f21f-43ae-43b4-92f3-f4af67cdf544",
      "first_name": "Tom",
      "last_name": "Jones",
      "email": "Tom.jones@climbing.com",
      "status": "active"
    }
  ],
  "children": [],
  "current_balance": 0
}
```

#### 409: Conflict - the site syncs its companies from its eCommerce platform, so an API key can't change its companies, sections, company addresses or company roles

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

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